initialize the EA Changing from timeframe to another

 

Hello

I have noticed something it is weird to me. I made an EA and attached to the chart and run as good as i want, but when i change the timeframe to an other on the same chart, the EA start up its functions again. I know when the EA removed from chart, EA calls Deinit() function, but in this case i noticed, when changing from timeframe to an other, the EA calls Deinit() function and calls Start() function again. So how to solve this problem in the new versions of MetaTrader platforms?

 
fx2013: I have noticed something it is weird to me. I made an EA and attached to the chart and run as good as i want, but when i change the timeframe to an other on the same chart, the EA start up its functions again. I know when the EA removed from chart, EA calls Deinit() function, but in this case i noticed, when changing from timeframe to an other, the EA calls Deinit() function and calls Start() function again. So how to solve this problem in the new versions of MetaTrader platforms?
It goes through de-init, init and start_once. The best solution depends on your problem which isn't clear to me. If you have global variables which are being compounded in init (for example) here. Then you'll need to modify your codes accordingly by either using functions which doesn't depend on static/global variables. Or identify when the terminal goes through de-init and ignore stuff.
 
fx2013:

Hello

I have noticed something it is weird to me. I made an EA and attached to the chart and run as good as i want, but when i change the timeframe to an other on the same chart, the EA start up its functions again. I know when the EA removed from chart, EA calls Deinit() function, but in this case i noticed, when changing from timeframe to an other, the EA calls Deinit() function and calls Start() function again. So how to solve this problem in the new versions of MetaTrader platforms?

Don't change timeframe on a chart with an EA on it. Open a second chart for the same symbol and change timeframes on that chart.
Reason: