In EA when I make a Variable in the Global Scope it is Initialize only once at the beginning of the program. And it doesn't get reinitialize/its value change to the original value when Time Frames change. But when I try the same concept on an Indicator, I found that the variables in the global scope gets reinitialize.
Is there a way to get the indicator works in the same way as the EA ?
Thanks in advance.
Yep
//-- For EA datetime prevTime; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { prevTime = Time[0]; Print("EA : prevTime = ",prevTime); return(INIT_SUCCEEDED); } //-- For Indicator(same thing) datetime prevTime = Time[0]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { Print("Indicator : prevTime = ",prevTime); return(INIT_SUCCEEDED); }
Yep
That will not prevent the indicator from re-initialising the variable when the timeframe is changed.
The OP could possibly use Terminal Global Variables, but would need to check if the variable exists before giving it a value and then delete it manually when the variable needs to be reset.
That will not prevent the indicator from re-initialising the variable when the timeframe is changed.
The OP could possibly use Terminal Global Variables, but would need to check if the variable exists before giving it a value and then delete it manually when the variable needs to be reset.
Hello Keith, Thanks for the reply.
Yes GlobalVariables could be of a help.
Is there anything mentioned in the documentation about this global(scope) variable re-initialization during a time frame change in indicators, because this doesn't happen on the EA ?, If there is I must have missed it.
Again Thanks both of you for your answers.
Nope.Nope, indicators get reloaded.Indicators use to do the same thing, now they are always reloaded.Silent, undocumented change.
Hello @whroeder1 Thanks for your answers.
Then it seems I have to use GlobalVariables(of the terminal) in these cases.
Anyway it is pretty weird that this happens only on indicator.
Thanks all for your time, much appreciated.. :)
Hello guys, its kind of mentioned in the documentation indirectly (I missed this part. LOL :D),
"In case the symbol or timeframe of a chart, to which the Expert Advisor is attached, changes, Expert Advisors are not loaded or unloaded. In this case client terminal subsequently calls OnDeinit() handlers on the old symbol/timeframe and OnInit() on the new symbol/timeframe (if they are such), values of global variables and static variables are not reset. All events, which have been received for the Expert Advisor before the initialization is completed (OnInit() function) are skipped."
This has mentioned under the Expert Advisor unloading, as a special feature relevant to EAs only, so this kind of indirectly says that it does not happen to indicators.
- www.mql5.com
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
In EA when I make a Variable in the Global Scope it is Initialize only once at the beginning of the program. And it doesn't get reinitialize/its value change to the original value when Time Frames change. But when I try the same concept on an Indicator, I found that the variables in the global scope gets reinitialize.
Is there a way to get the indicator works in the same way as the EA ?
Thanks in advance.