public override void Update() { if (Bars.CurrentBar == 0) { dynamicR.Add(Bars.High[0]); dynamicS.Add(Bars.Low[0]); } double newDynamicR = Formula.Highest(Bars.High, lookbackPeriod, 0); double newDynamicS = Formula.Lowest(Bars.Low, lookbackPeriod, 0); if (newDynamicR != Bars.High[0] && newDynamicR < prevDynamicR) { newDynamicR = prevDynamicR; newDynamicRCount++; if (newDynamicR != dynamicR[0] && newDynamicRCount > confirmBars) { newDynamicRCount = 0; dynamicR.Add(newDynamicR); CalcTrend(); } } if (newDynamicS != Bars.Low[0] && newDynamicS > prevDynamicS) { newDynamicS = prevDynamicS; newDynamicSCount++; if (newDynamicS != dynamicS[0] && newDynamicSCount > confirmBars) { newDynamicSCount = 0; dynamicS.Add(newDynamicS); CalcTrend(); } } Chart.DrawBox(Color.Red, Bars.CurrentBar, dynamicS[0]); Chart.DrawBox(Color.Blue, Bars.CurrentBar, dynamicR[0]); if (ShowMidpoint) { DynamicM = (newDynamicS + newDynamicR) / 2; Chart.DrawBox(Color.Yellow, Bars.CurrentBar, DynamicM); } if (IsDebug) { DebugSummary(); } prevDynamicR = newDynamicR; prevDynamicS = newDynamicS; }
public override bool OnIntervalClose() { int newCode = lrGraph.Code; // switch( newCode) { // case 1: newCode = 0; break; // case 6: newCode = 7; break; // } stretch[0] = newCode; if (newCode != lastCode) { // Got a code change, close out the previous one. if (lastCodes.Count > 2) { int combinedCode = lastCodes[1] * 8 + lastCodes[0]; CodeStats codeStats; if (codes.TryGetValue(combinedCode, out codeStats)) { codeStats.Count++; codeStats.CountBars += (Bars.CurrentBar - lastBar); codeStats.ProfitLoss += (Bars.Close[0] - lastPrices[0]); codes[combinedCode] = codeStats; } else { codeStats.Count = 1; codeStats.CountBars = 1; codeStats.ProfitLoss = 0; codes[combinedCode] = codeStats; } } // Alright start the new code. lastCodes.Add(newCode); lastPrices.Add(Bars.Close[0]); if (lastCodes.Count > 2) { int combinedCode = lastCodes[1] * 8 + lastCodes[0]; TradeDecision(combinedCode); } lastBar = Bars.CurrentBar; lastCode = newCode; } else { } // switch( lrGraph.Code) { // case 0: TradeSignal.GoShort(); break; // case 1: TradeSignal.GoShort(); break; // case 2: TradeSignal.GoShort(); break; // case 3: TradeSignal.GoShort(); break; // case 4: TradeSignal.GoLong(); break; // case 5: TradeSignal.GoLong(); break; // case 6: TradeSignal.GoLong(); break; // case 7: TradeSignal.GoLong(); break; // } return(true); }
public override bool OnIntervalClose() { price.Add(externalPrice[0]); UpdateAverage(); double y = top[5]; if (Count > 2) { top[0] = this[displace] + IntervalDefault.Period * 2; bottom[0] = this[displace] - IntervalDefault.Period * 2; center[0] = this[displace]; } return(true); }
private void CalcFTT(Bars bars) { if (highMaxVolume.Count == 0) { highMaxVolume.Add(0); } else { highMaxVolume.Add(highMaxVolume[0]); } if (lowMaxVolume.Count == 0) { lowMaxVolume.Add(0); } else { lowMaxVolume.Add(lowMaxVolume[0]); } if (bars.High[0] > fttHighestHigh && bars.High[0] > bars.High[1]) { if (bars.Volume[0] > highMaxVolume[0]) { highMaxVolume[0] = bars.Volume[0]; } fttHighestHigh = bars.High[0]; } if (bars.Low[0] < fttLowestLow && bars.Low[0] < bars.Low[1]) { if (bars.Volume[0] > lowMaxVolume[0]) { lowMaxVolume[0] = bars.Volume[0]; log.Debug("Low Max Volume Set to " + lowMaxVolume[0]); } fttLowestLow = bars.Low[0]; } }
/// <summary> /// Initializes this instance, registers all Integers and Doubles /// </summary> protected void Init() { var t = GetType(); if (MetricsExtensions.CachedMetricsDefinitions.ContainsKey(t.FullName)) { MetricsExtensions.CachedMetricsDefinitions[t.FullName].SetTo(this); return; } PropertyInfo[] props = t.GetProperties(BindingFlags.Instance | BindingFlags.Public); props = props.ToList().OrderBy(x => x.Name).ToArray(); foreach (var p in props) { if (p.hasAttribute(imbAttributeName.measure_excludeFromMetrics)) { IgnoreComputations.Add(p); IgnoreComputationsDict.Add(p.Name, p); continue; } if (p.GetIndexParameters().Length == 0) { if (p.PropertyType == typeof(Int32)) { Integers.Add(p); IntegersDict.Add(p.Name, p); } else if (p.PropertyType == typeof(Double)) { Doubles.Add(p); DoublesDict.Add(p.Name, p); } else if (p.PropertyType == typeof(Decimal)) { Decimals.Add(p); DecimalsDict.Add(p.Name, p); } } } MetricsExtensions.StoreMetricsDefinition(this); }
public void CheckForConfirmedPivot() { if (drawHigh && Bars.Low[0] <= lastHighPrice - threshold) { if (zagBars.Count == 0 || lastHighBar > zagBars[0]) { zigBars.Add(lastHighBar); zigHighs.Add(lastHighPrice); drawHigh = false; if (zagBars.Count > 0) { Chart.DrawLine(Drawing.Color, zagBars[0], lastLowPrice, zigBars[0], lastHighPrice, LineStyle.Solid); // DrawDownTrend(); // DrawHorizontal(lastHighPrice-100); LogNewHigh(); lastLowPrice = int.MaxValue; } } } else if (!drawHigh && Bars.High[0] >= lastLowPrice + threshold) { if (zigBars.Count == 0 || lastLowBar > zigBars[0]) { zagBars.Add(lastLowBar); zagLows.Add(lastLowPrice); drawHigh = true; if (zigBars.Count > 0) { Chart.DrawLine(Drawing.Color, zagBars[0], lastLowPrice, zigBars[0], lastHighPrice, LineStyle.Solid); // DrawUpTrend(); // DrawHorizontal(lastLowPrice+100); LogNewLow(); lastHighPrice = 0; } } } }
public virtual void AddDetail(string key, object value) { if (value is Guid) { Ids.Add(key, (Guid)value); } else if (value is string) { Strings.Add(key, (string)value); } else if (value is int) { Ints.Add(key, (int)value); } else if (value is double) { Doubles.Add(key, (double)value); } else { Strings.Add(key, value.ToString()); } }
public void Add(double value) { indicator.Add(value); }
public override bool OnIntervalClose() { double currLow = Bars.Low[0]; if (lowest == 0) { lowest = currLow; } else { if (currLow < lowest) { lowest = currLow; } } // DO NOT DELETE : Turn to hidden instead if necessary. this[0] = lowest; pivot = 0; pivotBar = 0; for (int mainLoop = rightStrength; mainLoop < length; mainLoop++) { pivotPassed = true; leftPassed = true; pivotHigh = Bars.High[mainLoop] + 1; for (int i = mainLoop - rightStrength; i < mainLoop; i++) { if (pivotHigh < Bars.High[i]) { pivotPassed = false; break; } } if (pivotPassed) { for (int i = mainLoop + 1; i <= mainLoop + leftStrength; i++) { if (pivotHigh < Bars.High[i]) { leftPassed = false; break; } } } if (leftPassed && pivotPassed) { pivot = pivotHigh; pivotBar = mainLoop; break; } } if (leftPassed && pivotPassed && (pivotHighs.Count == 0 || pivot != pivotHighs[0])) { if (pivot > this[pivotBar]) { lowest = pivot; pivotHighs.Add(pivot); int bar = Bars.CurrentBar - pivotBar; pivotBars.Add(bar); Elapsed elapsed = default(Elapsed); if (pivotBars.Count > 1) { elapsed = Bars.Time[pivotBar] - Bars.Time[Bars.CurrentBar - pivotBars[1]]; } if (!disableBoxes) { Chart.DrawBox(Drawing.Color, bar, pivot); if (pivotBars.Count > 1) { Log.Debug("|Pivot High," + Bars.Time[pivotBar] + "," + elapsed.TotalSeconds + "," + Bars.Time[pivotBar] + "," + Bars.Time[Bars.CurrentBar - pivotBars[1]]); } } } } return(true); }
public void Add(double value) { output.Add(value); }
public override bool OnIntervalClose() { double currHigh = Bars.High[0]; if (highest == 0) { highest = currHigh; } else { if (currHigh > highest) { highest = currHigh; } } // DO NOT DELETE. Turn to hidden instead if necessary. this[0] = highest; pivot = 0; for (int MAINLOOP = RSTREN; MAINLOOP < LENGTH; MAINLOOP++) { rightPassed = true; leftPassed = true; SHBAR = Bars.Low[MAINLOOP] - 1; for (int VALUE1 = MAINLOOP - RSTREN; VALUE1 <= MAINLOOP - 1; VALUE1++) { if (SHBAR > Bars.Low[VALUE1]) { rightPassed = false; break; } } if (rightPassed) { for (int VALUE1 = MAINLOOP + 1; VALUE1 <= MAINLOOP + LSTREN; VALUE1++) { if (SHBAR > Bars.Low[VALUE1]) { leftPassed = false; break; } } } if (rightPassed && leftPassed) { pivot = SHBAR; pivotBar = MAINLOOP; break; } } if (leftPassed && rightPassed && (pivotLows.Count == 0 || pivot != pivotLows[0])) { if (pivot < this[pivotBar]) { highest = pivot; pivotLows.Add(pivot); int bar = Bars.CurrentBar - pivotBar; pivotBars.Add(bar); Elapsed elapsed = default(Elapsed); if (pivotBars.Count > 1) { elapsed = Bars.Time[pivotBar] - Bars.Time[Bars.CurrentBar - pivotBars[1]]; } if (!disableBoxes) { Chart.DrawBox(Drawing.Color, bar, pivot); if (pivotBars.Count > 1) { Log.Debug("|Pivot Low," + Bars.Time[pivotBar] + "," + elapsed.TotalSeconds + "," + Bars.Time[pivotBar] + "," + Bars.Time[Bars.CurrentBar - pivotBars[1]]); } } } } return(true); }
public override void SubReportChanged(SubReportEvent newstate, string newgroup) { base.SubReportChanged(newstate, newgroup); Evaluator eval; eval = Report.Evaluator; switch (newstate) { case SubReportEvent.Start: FExportValue = new Variant(); FIsPartial = false; FForcedPartial = false; FOldString = ""; FUpdated = false; FDataCount = 0; if (Aggregate != Aggregate.None) { try { // Update with the initial value eval.Expression = AgIniValue; eval.Evaluate(); Value = eval.Result; FSumValue = Value; FUpdated = true; } catch (Exception E) { throw new ReportException(E.Message + ":Expression-" + Name + " Prop:AgIniValue", this, "AgIniValue"); } } break; case SubReportEvent.SubReportStart: FExportValue = new Variant(); FIsPartial = false; FForcedPartial = false; FOldString = ""; FUpdated = false; FDataCount = 0; if ((Aggregate != Aggregate.None) && (Aggregate != Aggregate.General)) { try { // Update with the initial value eval.Expression = AgIniValue; eval.Evaluate(); Value = eval.Result; FSumValue = Value; FUpdated = true; } catch (Exception E) { throw new ReportException(E.Message + ":Expression-" + Name + " Prop:AgIniValue", this, "AgIniValue"); } } break; case SubReportEvent.DataChange: FIsPartial = false; FForcedPartial = false; FUpdated = false; FDataCount++; if (Aggregate != Aggregate.None) { try { eval.Expression = Expression; eval.Evaluate(); // Do the operation switch (AgType) { case AggregateType.Summary: if (eval.Result.VarType != VariantType.Null) { Value = Value + eval.Result; } break; case AggregateType.Minimum: if (eval.Result.VarType != VariantType.Null) { if (Value > eval.Result) { Value = eval.Result; } } break; case AggregateType.Maximum: if (eval.Result.VarType != VariantType.Null) { if (Value < eval.Result) { Value = eval.Result; } } break; case AggregateType.Average: if (eval.Result.VarType == VariantType.Null) { FDataCount--; } else { FSumValue = FSumValue + eval.Result; Value = FSumValue / FDataCount; } break; case AggregateType.StandardDeviation: if (eval.Result.VarType == VariantType.Null) { FDataCount--; } else { FValues.Add(eval.Result); Value = DoubleUtil.StandardDeviation(FValues); } break; } FUpdated = true; } catch (Exception E) { throw new ReportException(E.Message + ":Expression-" + Name + " Prop:Expression", this, "Expression"); } } break; case SubReportEvent.GroupChange: FIsPartial = false; FForcedPartial = false; FUpdated = false; FOldString = ""; if (Aggregate == Aggregate.Group) { if (GroupName.ToUpper() == newgroup.ToUpper()) { // Update with the initial value try { // Update with the initial value eval.Expression = AgIniValue; eval.Evaluate(); Value = eval.Result; FSumValue = Value; FUpdated = true; } catch (Exception E) { throw new ReportException(E.Message + ":Expression-" + Name + " Prop:AgIniValue", this, "AgIniValue"); } } } break; case SubReportEvent.PageChange: FOldString = ""; if (Aggregate == Aggregate.None) { // Page variable must be recalculated FUpdated = false; } if (Aggregate == Aggregate.Page) { // Update with the initial value try { // Update with the initial value eval.Expression = AgIniValue; eval.Evaluate(); Value = eval.Result; FSumValue = Value; FUpdated = true; } catch (Exception E) { throw new ReportException(E.Message + ":Expression-" + Name + " Prop:AgIniValue", this, "AgIniValue"); } SubReportChanged(SubReportEvent.DataChange, ""); } break; case SubReportEvent.InvalidateValue: FIsPartial = false; FForcedPartial = false; FOldString = ""; FUpdated = false; break; } }