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

- www.mql5.com
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.
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.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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.