I wrote an indicator that renders a rectangle when the High of the current candle is higher than the previous one. The indicator works, but when I add a second series of data, it paints them for a moment until the price updates, and then they all disappear. I suppose that the chart takes into account each candle from both data series and there is some conflict. What do I need to change so that in OnRender it only accesses the main data series and not the second one? Here I include the original code with the second data series commented out for it to work :
protected override void OnBarUpdate()
{
if (CurrentBars[0] < BarsRequiredToPlot /*|| CurrentBars[1] < BarsRequiredToPlot*/ )
{return;}
if (BarsInProgress == 0 )
{
HigherHigh[0] = false;
if (High[0] > High[1])
{HigherHigh[0] = true;}
}
}
protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
{
for (int index = ChartBars.FromIndex; index <= ChartBars.ToIndex; index++)
{
float xStart = chartControl.GetXByBarIndex(ChartBars, index );
float yStart = chartScale.GetYByValue(High.GetValueAt(index) + 5 * TickSize);
float width = 6;
SharpDX.RectangleF rect = new SharpDX.RectangleF(xStart-width/2, yStart, width, 10);
// define the brush used in the rectangle
SharpDX.Direct2D1.SolidColorBrush customDXBrush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.Lime);
SharpDX.Direct2D1.SolidColorBrush outlineBrush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.Black);
if (Bars.GetHigh(index)>Bars.GetHigh(index-1))
if (HigherHigh.GetValueAt(index) == true)
{
RenderTarget.FillRectangle(rect, customDXBrush);
RenderTarget.DrawRectangle(rect, outlineBrush, 1);
}
// always dispose of a brush when finished
customDXBrush.Dispose();
outlineBrush.Dispose();
}
// Default plotting in base class. Should be left Uncommented if indicators holds at least one plot you want displayed
base.OnRender(chartControl, chartScale);
}
Thanks so much!
Comment