I am drawing a kind of high low zigzag line, which is not displayed by the standard plot (all values except the highs and lows are reset). I am using the OnRender() PathGeometry and sink.AddLine, but need to dynamically change the line color based on the angle of the line (previousValue>currentValue or previousValue<currentValue).
How can I change the brush color setting while the path is open, and I add lines?
Here is the relevant part of the code
... bool previousPoint = previousInx > -1; double previousValue; double currentValue; // find current points for (int idx = ChartBars.FromIndex; idx <= ChartBars.ToIndex; idx++) {[INDENT]if (idx < startIndex [/INDENT][INDENT=2]|| idx > Bars.Count - (Calculate == NinjaTrader.NinjaScript.Calculate.OnBarClose ? 1 : 0) || idx < Math.Max(BarsRequiredToPlot, 0))[/INDENT][INDENT]continue; if (!zigZagSeries.IsValidDataPointAt(idx))[/INDENT][INDENT=2]continue;[/INDENT][INDENT] currentValue = zigZagSeries.GetValueAt(idx); x2 = (chartControl.BarSpacingType == BarSpacingType.TimeBased [/INDENT][INDENT=2]|| chartControl.BarSpacingType == BarSpacingType.EquidistantMulti && idx >= ChartBars.Count[/INDENT][INDENT=3]? chartControl.GetXByTime(ChartBars.GetTimeByBarIdx( chartControl, idx)) : chartControl.GetXByBarIndex(ChartBars, idx));[/INDENT][INDENT]y2 = chartScale.GetYByValue(currentValue); if (sink == null) {[/INDENT][INDENT=2]if (!previousPoint) // first is in the chart, run again {[/INDENT][INDENT=3]x1 = x2; y1 = y2; previousValue = currentValue; previousPoint = true; continue;[/INDENT][INDENT=2]}[/INDENT][INDENT] [/INDENT][INDENT=2]g = new SharpDX.Direct2D1.PathGeometry(Core.Globals.D2DFac tory); sink = g.Open(); sink.BeginFigure(new SharpDX.Vector2(x1, y1), SharpDX.Direct2D1.FigureBegin.Hollow);[/INDENT][INDENT]} if (previousValue.ApproxCompare(currentValue) < 0) {[/INDENT][INDENT=2]//Set Trend Up color[/INDENT][INDENT]} else {[/INDENT][INDENT=2]//Set Trend Down color[/INDENT][INDENT]} sink.AddLine(new SharpDX.Vector2(x2, y2)); previousValue = currentValue;[/INDENT] } ...
Comment