The terminology you are seeking for is "persistence".
We refer to "it" as the persistence protocol.
People differ in their method of implementing a persistence protocol, inasmuch as we differ in our very coding styles.
My style is to log the requisite persisting information into a csv file. This csv file is opened and its contents are read/loaded during the init(). The log file is updated in start() as needed, as well as updated in deinit().
In other industries we refer to this file as the "checkpoint" file.
[...] as a OS crash/power failure etc won't call deinit.
Which is exactly why deinit() could be used in a persistence layer to distinguish between an unexpected failure (OS/Terminal crash) to an expected failure ('graceful' closure of Terminal by the user).
lol, I was going to post the EXACT same thing but you beat me to it :)
what if a bad configured server installs some updates and autorestarts?
from my point of view that is a unplanned unexpected failure but i think deinit would be called...
would be cool if we can read the reason why deinit is being called.
but, my failsave routine is called at every change of the internal state.
zzuegg:
[...] would be cool if we can read the reason why deinit is being called.
ya. i knew that. but it would be interesting if we can differ between
a)MetaTrader is beeing shot down by user
b)windows shutdown
c)windows restart.
especially the last two. because i would close all open orders on shutdown, but not on a restart.
[...]
b)windows shutdown
c)windows restart.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have an idea for coding an EA, but at very first stage I found out that it would start making losses if by any reason MT4 would be switched off and on again. I need my EA to remember a set of data (an array to be specific) no matter what. I couldn't find any solution anywhere on the internet. My best idea is to store data in/as labels on the chart. They are not deleted nor lost when MT4 is turned off. Anyways I do believe there is a better way to do that, some kind of comand or function perhaps... I'm not that experienced programmer so I turn to more skilled fellows. I will really appreciate any ideas.
Max