Download MetaTrader 5

Timeframe change re-sizes array to declared size

To add comments, please log in or register
ArjanV
18
ArjanV  

Dear all,

 

Hope anybody can answer the following questions relating to the use of arrays in indicators:

Is it correct that an global array is re-declared once the change of the timeframe of the chart causes the indicator to go through the DeInit and Init functions? 

 I see the size of a particular (globally declared) array change to the declared size (of 1) once the DeInit function ends and the Init function is called caused by a change of the timeframe of the chart. 

 The array is of the datetime type and 1-dimensional, storing object datetime locations. Datetime values of newly placed objects are added to the array (resized by +1 for every object added). All resizing taking place inside of the Start function. The idea is to use the datetime information in the array to redraw the objects when the timeframe of the chart is changed (at the same datetime but at a newly calculated vertical location). However, the timeframe change now seems to re-declare the array to its original size and so all elements are gone after going through the deinit and init functions.

If this is expected behavior, how can it be handled correctly?

 Thanks for helping me, reading through dozens of forum pages and the online documentation didn't get me any further, hope anyone knows the answer. 

Keith Watford
Moderator
9641
Keith Watford  

Yes, Globally declared variables are reset in an indicator.

You could either store the datetime values in a file or include the time as a string in the object name. Then you should be able to retrieve the times in Imit.

ArjanV
18
ArjanV  
Keith Watford:

Yes, Globally declared variables are reset in an indicator.

You could either store the datetime values in a file or include the time as a string in the object name. Then you should be able to retrieve the times in Imit.

Very clear answer Keith, thanks for clarifying this and pointing me in the right direction !

To add comments, please log in or register