Download MetaTrader 5
To add comments, please log in or register
Interested in MQL5 features? Find them in documentation!
honest_knave
970
honest_knave 2014.07.07 18:56 

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?

Keith Watford
Moderator
8027
Keith Watford 2014.07.07 20:27  

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. 

Ian Venner
2583
Ian Venner 2014.07.08 00:23  
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
whroeder1
13656
whroeder1 2014.07.08 11:58  
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.
honest_knave
970
honest_knave 2014.07.08 14:35  

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 

/
To add comments, please log in or register