OK, it seems the trick is NOT to set the variable within OnInit().
I shall declare it and set it outside OnInit().
int TF = Period();
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
In the code above, TF contains the output of Period(). Of course, it stands for "Timeframe".
My problem is, when I change the TF on the chart, OnInit() is run again and the TF changes accordingly.
What I want is for the variable to be evaluated only once, when the EA or indicator is loaded, and commit to that value forever.
How can I do that?