How to stop EA from Deinit and init again when period change

 

hello,

i have created a Semi Automated EA that gives me signals.

problem is that in the same time that my EA is Attached to 15Min charts in 8 different Currency Pairs, I need to keep changing the time Frames to Verify the signals.

and every time that i Change the time frame, EA Automaticly Deinits and swiftly Inits again in the new time frame, and i do not want that, because the global Variables starts fresh with value of zero.

i already know about the taskbar in MT4 : Tools > Options > Disable Automated Trading when the charts Symbol or Period Has Been Changed.

i turned that option off and still this problem exist.

i have searched the forum for an answer but i could not find any.

can anyone show me the way to stop the EA from  Deinit and init again when period changes.

thank you in advance.

 
kriss.ro: can anyone show me the way to stop the EA from  Deinit and init again when period changes.
No one can, because it always occurs.
kriss.ro: and i do not want that, because the global Variables starts fresh with value of zero.
EAs are not reloaded. Your variables have not changed. Stop resetting them except for the first time.
 

Events deinit -> init will inevitably be generated by the terminal when the timeframe changes.

https://www.mql5.com/en/docs/runtime/event_fire

Init #

Immediately after the client terminal loads a program (an Expert Advisor or custom indicator) and starts the process of initialization of global variables, the Init event will be sent, which will be processed by OnInit() event handler, if there is such. This event is also generated after a financial instrument and/or chart timeframe is changed, after a program is recompiled in MetaEditor, after input parameters are changed from the setup window of an Expert Advisor or a custom indicator. An Expert Advisor is also initialized after the account is changed. The Init event is not generated for scripts.

Deinit #

Before global variables are deinitialized and the program (Expert Advisor or custom indicator) is unloaded, the client terminal sends the Deinit event to the program. Deinit is also generated when the client terminal is closed, when a chart is closed, right before the security and/or timeframe is changed, at a successful program re-compilation, when input parameters are changed, and when account is changed.

The deinitialization reason can be obtained from the parameter, passed to the OnDeinit() function. The OnDeinit() function run is restricted to 2.5 seconds. If during this time the function hasn't been completed, then it is forcibly terminated. The Deinit event is not generated for scripts.

Everything from the quote above is true for MT4 too. If I'm not mistaken. You can find these events in the MQL4 documentation and compare with MQL5 if you want. It’s just that the MQL5 documentation is more convenient
 
Either make your EA analyze M15 regardless of the current timeframe (which can be relatively difficult) or don't change the timeframe on those charts (open new copies of the charts and change the timeframe on them)
 

thank you All for your help.

i kept thinking maybe i was missing something.

thank you.