Beginner's question: help with globals

 

I understand that MT handles global variables, so. I have a misunderstanding that I hope someone might help clear up. I have understood that the EA runs top to bottom each tick. If so, how does one maintain persistent global values when the variables are initialized each time?


Is it that only the start() section reruns and that the init/deint sections run once?


Do my own functions need to be within start() or can they be written along side?


Thanks for any help.

 

init() runs once.


deinit() runs once for a maximum of 2500 ms.


start() runs on each tick on condition that it is idle when the tick arrives.


Your functions are coded outside of all the other function blocks. The order does not matter. Where you call them from obviously matters.


Variables declared outside of all functions are available to all functions.


Variables declared within a function are available only to that function.


Within a function if you wish to stop the variable being initialized each time that function runs, you can declare it as static - then it will only be initialized on first run of the function.


There is another (even more global) type of variable which are shared across MT4 platform instances and they have their own functions to initialize, set, query etc.


CB

Reason: