Manual changing of the TF restart the EA and makes my warning message box appear each time.

 

I noticed that with every manual change of time-frame EA is restarting.

Sometimes it makes some difficulties for me.

In the project I'm currently working on, every time user runs the EA some conditions have to be in checked OnInit() and if necessary,   a message box will appear to give him a warning.

If user decide to continue using the EA with the same setting, then,It becomes annoying when he sees the same message box with every time-frame changing.

The same thing is happening when he changes some other parameters in the parameters window and press OK, but this is more acceptable.

Please let me know if there is a way to solve this problem.

Thanks

 
The OnDeinit() function (https://docs.mql4.com/basis/function/events) takes in a parameter that tells your code the reason for de-initialization. So you can check that if it is called due to chart TF change, set a flag such that when your OnInit() runs again, it won't pop up the message box.
Event Handling Functions - Functions - Language Basics - MQL4 Reference
Event Handling Functions - Functions - Language Basics - MQL4 Reference
  • docs.mql4.com
The MQL4 language provides processing of some predefined events. Functions for handling these events must be defined in a MQL4 program; function name, return type, composition of parameters (if there are any) and their types must strictly conform to the description of the event handler function. The event handler of the client terminal...
 
Seng Joo Thio:
The OnDeinit() function (https://docs.mql4.com/basis/function/events) takes in a parameter that tells your code the reason for de-initialization. So you can check that if it is called due to chart TF change, set a flag such that when your OnInit() runs again, it won't pop up the message box.

Thanks  Seng Joo Thio, 

That was perfect.
How to save that value while EA is restarting and losing it's collected values?

I have 2 ideas for it but I also want to know if you have a better idea.

I can write this value down on a csv file or use a terminal global variable.

Is it the right way?

 
Reza nasimi:

Thanks  Seng Joo Thio, 

That was perfect.
How to save that value while EA is restarting and losing it's collected values?

I have 2 ideas for it but I also want to know if you have a better idea.

I can write this value down on a csv file or use a terminal global variable.

Is it the right way?

You can use any global variable - they don't get re-initialized when the chart's timeframe changes.

Another way is to forget about using any flag/variable... just call UninitializeReason() in OnInit() to find out whether it is a cold start, and if not, the reason for restarting... (according to  https://docs.mql4.com/constants/namedconstants/uninit).
Uninitialization Reason Codes - Named Constants - Constants, Enumerations and Structures - MQL4 Reference
Uninitialization Reason Codes - Named Constants - Constants, Enumerations and Structures - MQL4 Reference
  • docs.mql4.com
//| get text description                                             | //| Expert deinitialization function                                 |
 
Seng Joo Thio:

You can use any global variable - they don't get re-initialized when the chart's timeframe changes.

Another way is to forget about using any flag/variable... just call UninitializeReason() in OnInit() to find out whether it is a cold start, and if not, the reason for restarting... (according to  https://docs.mql4.com/constants/namedconstants/uninit).

Thanks a lot  Seng Joo Thio

Perfect.

Reason: