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++) {if (idx < startIndex|| idx > Bars.Count - (Calculate == NinjaTrader.NinjaScript.Calculate.OnBarClose ? 1 : 0) || idx < Math.Max(BarsRequiredToPlot, 0))continue; if (!zigZagSeries.IsValidDataPointAt(idx))continue;currentValue = zigZagSeries.GetValueAt(idx); x2 = (chartControl.BarSpacingType == BarSpacingType.TimeBased|| chartControl.BarSpacingType == BarSpacingType.EquidistantMulti && idx >= ChartBars.Count? chartControl.GetXByTime(ChartBars.GetTimeByBarIdx( chartControl, idx)) : chartControl.GetXByBarIndex(ChartBars, idx));y2 = chartScale.GetYByValue(currentValue); if (sink == null) {if (!previousPoint) // first is in the chart, run again {x1 = x2; y1 = y2; previousValue = currentValue; previousPoint = true; continue;}g = new SharpDX.Direct2D1.PathGeometry(Core.Globals.D2DFac tory); sink = g.Open(); sink.BeginFigure(new SharpDX.Vector2(x1, y1), SharpDX.Direct2D1.FigureBegin.Hollow);} if (previousValue.ApproxCompare(currentValue) < 0) {//Set Trend Up color} else {//Set Trend Down color} sink.AddLine(new SharpDX.Vector2(x2, y2)); previousValue = currentValue;} ...
Comment