In an expert adviser, in the OnTick() function, is there a way to set a global variable that will retain its value it had during the previous call? I'm looking for a variable that won't re-initialize with each new tick.
- Copilot coding assistant - Developing programs
- MetaEditor - Professional editor of trading applications
- MQL5 Wizard: Development of trading robots for MetaTrader 5
theDUDE:
In an expert adviser, in the OnTick() function, is there a way to set a global variable that will retain its value it had during the previous call? I'm looking for a variable that won't re-initialize with each new tick.
In an expert adviser, in the OnTick() function, is there a way to set a global variable that will retain its value it had during the previous call? I'm looking for a variable that won't re-initialize with each new tick.
Hi theDUDE,
Come on, you can solve this yourself :), don't kidding around, we know you can solve this, it just a matter of coding.
In any EA, CI or Script:
double My_Var = 0.0; // this is set as global variable or static local variable OnTick() { if (My_Var == 0.0) My_Var = 1.618; //--- codes and codes goes here if (re_initialize == true) My_Vars = 0.0; // re-initialize again on next tick. }
click that delete link dude :)

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