I've been tweaking the HeikenAshi 8 indicator by PaulH in an attempt to learn more about SharpDX, RenderTargets, etc.
I'm trying to color individual candle bodies on UP candles based on a certain condition and DOWN candles for the reverese condition, but it colors all of the UP candles (or the DOWN ones) on the chart when the relevant condition is met rather than the individual ones that meet the condition.
In the following section of the code what part would I be looking at in order to start heading towards a solution?
Thanks
protected override void OnRender(ChartControl chartControl, ChartScale chartScale) { if (Bars == null || ChartControl == null) return; int barPaintWidth = Math.Max(3, 1 + 2 * ((int)ChartControl.BarWidth - 1) + 2 * shadowWidth); for (int idx = ChartBars.FromIndex; idx <= ChartBars.ToIndex; idx++) { if (idx - Displacement < 0 || idx - Displacement >= BarsArray[0].Count || ( idx - Displacement < BarsRequiredToPlot)) continue; double valH = HAHigh.GetValueAt(idx); double valL = HALow.GetValueAt(idx); double valC = HAClose.GetValueAt(idx); double valO = HAOpen.GetValueAt(idx); int x = chartControl.GetXByBarIndex(ChartBars, idx); //was chartControl.BarsArray[0] int y1 = chartScale.GetYByValue(valO); int y2 = chartScale.GetYByValue(valH); int y3 = chartScale.GetYByValue(valL); int y4 = chartScale.GetYByValue(valC); SharpDX.Direct2D1.Brush shadowColordx = shadowColor.ToDxBrush(RenderTarget); // prepare for the color to use var xy2 = new Vector2(x, y2); var xy3 = new Vector2(x, y3); RenderTarget.DrawLine(xy2, xy3, shadowColordx, shadowWidth); if (y4 == y1) RenderTarget.DrawLine( new Vector2( x - barPaintWidth / 2, y1), new Vector2( x + barPaintWidth / 2, y1), shadowColordx, shadowWidth); else { if (y4 > y1) { SharpDX.Direct2D1.Brush barColorDowndx = barColorDown.ToDxBrush(RenderTarget); // prepare for the color to use RenderTarget.FillRectangle( new RectangleF(x - barPaintWidth / 2, y1, barPaintWidth, y4 - y1), barColorDowndx); barColorDowndx.Dispose(); } else { SharpDX.Direct2D1.Brush barColorUpdx = barColorUp.ToDxBrush(RenderTarget); // prepare for the color to use RenderTarget.FillRectangle( new RectangleF(x - barPaintWidth / 2, y4, barPaintWidth, y1 - y4),barColorUpdx); barColorUpdx.Dispose(); } RenderTarget.DrawRectangle( new RectangleF( x - barPaintWidth / 2 + (float)shadowWidth / 2, Math.Min(y4, y1), barPaintWidth - (float)shadowWidth, Math.Abs(y4 - y1)), shadowColordx, shadowWidth); } shadowColordx.Dispose(); } }
Comment