Indicator buffer issue with more bars

 

Indicator added to chart, indicator buffers drawn correctly:

 

Now scroll back to the start of the chart, and keep scrolling back to add more bars. The indicator buffers seem to stay where they were before more bars were added, thus moving them into space.

 

Is this a documented issue, or am I just doing something stupid?

 

I have noticed that this happens unless an indicator recalculates the complete buffer array

I believe that it is to do with the way that the values are shifted when new bars are added, but I may be wrong.

Usually new bars are added at the far right of the chart and buffer values are shifted left so that they relate to the correct bar.

But if new bars are added to the far left, I think that the values are still shifted left so that they don't relate to the correct bar any more. 

 
Yes that occurs when you have gaps in the buffers. You need to reset all the buffer indexes to EMPTY_VALUE when prev_calculated == 0
 
honest_knave: Is this a documented issue,
Yes. The documentation states that the buffers are initialized to EMPTY_VALUE and not to call ArrayFill() in init(). On additional history, the buffer is expanded, but the initial elements are not reset.
Same problem occurs, for example setting a buffer on a MA cross. If bar zero uncrosses the buffer remains set.
Either clear the buffer when prev_calculated == 0 or always set buffer[i]=EMPTY_VALUE at the start of the loop.
 

Thank you for the replies.

I've been working around it but it just struck me as odd behaviour... I can't conceive any situation where someone would not wish to shift the elements a commensurate amount as the buffer size grows, yet it is something that needs to be manually overcome (albeit simply).

Not a problem, just an observation.

Thanks once again 

Reason: