Making my EA survive a restart without forgetting its state
Posted: Thu Oct 08, 2026 6:52 am
Making my EA survive a restart without forgetting its state
I restarted my platform once while the EA had open trades and it behaved strangely. It had lost track of things like which trades had already had a partial close, and how many trades it had taken that day. It took some clean up to fix.
The lesson was that anything the EA needs to remember across a restart can't live only in variables. Variables disappear when the program is removed or the platform restarts. Now I store the important bits where they persist: in global variables of the terminal, or in a small file.
What I save: the count of trades today, the daily starting balance, flags for partial closes keyed by the position ticket, and the time of the last trade for cooldowns. On startup, the EA reads those values and also scans the open positions to rebuild its picture. If something doesn't match, it logs a warning.
I test by deliberately stopping the platform mid trade on a demo, and restarting. It's easy to forget, but a restart will happen eventually, due to an update, a power cut or a mistake.
I restarted my platform once while the EA had open trades and it behaved strangely. It had lost track of things like which trades had already had a partial close, and how many trades it had taken that day. It took some clean up to fix.
The lesson was that anything the EA needs to remember across a restart can't live only in variables. Variables disappear when the program is removed or the platform restarts. Now I store the important bits where they persist: in global variables of the terminal, or in a small file.
What I save: the count of trades today, the daily starting balance, flags for partial closes keyed by the position ticket, and the time of the last trade for cooldowns. On startup, the EA reads those values and also scans the open positions to rebuild its picture. If something doesn't match, it logs a warning.
I test by deliberately stopping the platform mid trade on a demo, and restarting. It's easy to forget, but a restart will happen eventually, due to an update, a power cut or a mistake.