Handling MT5 restarts in an EA without duplicate orders
Posted: Sun Nov 01, 2026 1:53 pm
An EA that restarts, after a VPS reboot or a platform update, needs to know what it already did. Otherwise it can open a duplicate position.
Common causes of duplicates:
This is one of those features nobody notices until it fails.
How do you handle restarts in your EAs?
Common causes of duplicates:
- The EA uses an internal variable to remember "trade open", which resets to false on restart.
- A signal is still valid after the restart, so the EA acts on it again.
- Two terminals run the same EA on the same account after a recovery.
- On start, scan open positions and pending orders by magic number and symbol, and rebuild the internal state from them.
- Store the time of the last signal acted on in a global variable of the terminal or a file, and refuse to act on the same signal twice.
- Use a lock file or a global variable with the terminal ID, so a second instance knows it's not alone.
This is one of those features nobody notices until it fails.
How do you handle restarts in your EAs?