Hi,
I find that the static variable’s contend does not hold whenever i change timeframe, this does not happen to EA. Is this a MT4 bug?
whenever change of timeframe, init() is entered and always print the same content.
Think of an MQL indicator / EA as a program, not a subroutine and you will understand why. The init is done for every change made whether changing a setting or the TF.
In order to retain values from one invocation to another, you need to use Global variables. Very easy to use.
But EA static value never lost when change setting or TF, it works exactly what it should do as a static variable in C programming.
I had to resort to global variables for indicators, it is not difficult but I may have to manually clear the global variables if I want to restart the indicator.
I wanted to compare spread for different broker and would like to have a indicator to save the spread upon every tick, compute average, max, min and SD, wanted to save the spread in a static array, could be tens of thousand over a day, can’t posibly do it with global variable.
Thanks, I just want to confirm the behaviour. Guess I have no choice but to make it as EA, run it in a seperate window. I wouldn’t want file IO to slow down the whole system.
CodeMeister is correct. Static variables are no good for persistence. If you check the Experts tab when you change the timeframe, you will see your EA/indicator is de-initialised(effectively unloaded) and re-loaded.
I have done my own spread monitoring program and what works for me is to record the spreads into an Array, and then work the calculations on the spot. When I turn the platform off or de-init the EA, it records the calculated data to a small csv files which the EA then picks up next time it is used. It then carries on seamlessly.
The only real reason to record every tick of data is to make a chart of the spreads, which I found fun for the first few weeks, but the files become so big that they are eventually unmanageable.
I settle with indicator running in separate window, monitor for a few days to make comparison for a few brokers, just make sure I don’t Chang timeframe
EA also go through init and dinit when changing TF and static variables survive
This is a bug to a C programmer, any idea where we can feed back to developer?
CodeMeister is correct. Static variables are no good for persistence. If you check the Experts tab when you change the timeframe, you will see your EA/indicator is de-initialised(effectively unloaded) and re-loaded.