No, "static" does not mean read-only. It means that it retains its value even after returning from the function.
Also, instead of using a function please also see the following ...
Detecting the start of a new bar or candle
Fernando Carreiro, 2022.04.24 00:38
Detecting the start of a new bar or candle, in the OnTick() event handler of an expert advisor.

- www.mql5.com

- www.mql5.com
thank you for your quick reply and the link,
before discovering your code, which looks quite complete after a quick glance.
why, when the function is called a 2nd time, the variable previousTime is not initiated to 0 ? is it because it already exists and its value is greater than 0? or am I still missing the point ?
if the answer is in your link don't bother replying and thanks again.🙂
Because it is "static". As I state in my previous post, it retains its value. It does not lose its value when you return from a function, no matter how many times the function is called.
"Static variables exist from the moment of program execution and are initialized only once before the specialized functions OnInit() is called. If the initial values are not specified, variables of the static storage class are taking zero initial values.
Local variables declared with the static keyword retain their values throughout the function lifetime. With each next function call, such local variables contain the values that they had during the previous call. Any variables in a block, except formal parameters of a function, can be defined as static. If a variable declared on a local level is not a static one, memory for such a variable is allocated automatically at a program stack."

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
hi everyone, hope you're well
I found this function on this video here from @ Tobias Christian Witzigmann, can you confirm that the variable previousTime is read only once with al static function ?
I thought I understood that from the MQL5 code documentation, but I'd rather confirm it. or am I still missing the point?
Best Reguards,
ZeroCafeine