OnDeinit()

 

Hello! 

I want store some variables in my EA as GlobalVariable in case EA stops, so it can recover. My question is if EA stops for no reason ( power failure or terminal failure or internet loss) is the OnDeinit() function in the EA will run?

I am asking this because I want to delete all globals when I voluntarily stop the EA. 

 

Yes, you can delete all globals when you voluntarily stop the EA. You can specify the Deinit reason as condition. 

https://www.mql5.com/en/docs/event_handlers/ondeinit

Documentation on MQL5: Event Handling / OnDeinit
Documentation on MQL5: Event Handling / OnDeinit
  • www.mql5.com
OnDeinit - Event Handling - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
DannyBass:

Hello! 

I want store some variables in my EA as GlobalVariable in case EA stops, so it can recover. My question is if EA stops for no reason ( power failure or terminal failure or internet loss) is the OnDeinit() function in the EA will run?

I am asking this because I want to delete all globals when I voluntarily stop the EA. 

If the internet connection is lost, the EA will not stop as such, it will pause until a new tick comes in when the internet reconnects.

I don't think that OnDeinit will be called if the terminal crashes or there is a power failure as it cannot anticipate such events.

So, I believe that OnDeinit will only be called if you voluntarily close the EA/platform.

I'm sure that someone will correct me if I am wrong.

 
DannyBass: I want store some variables in my EA as GlobalVariable in case EA stops, so it can recover. My question is if EA stops for no reason ( power failure or terminal failure or internet loss) is the OnDeinit() function in the EA will run? I am asking this because I want to delete all globals when I voluntarily stop the EA. 

Obviously no, the OnDeinit is not called during a failure. That is why it is called a failure.

The only exception to your examples, would be a loss of network connection, as that would not be a failure leading to the computer, terminal, or the EA to "die" or terminate. It would continue to function to a degree.

EDIT: By the way, a controlled shutdown, when using a UPS, would not be considered a failure, as MetaTrader would receive a signal from the operating system to shutdown cleanly.

Reason: