Persisting News-Suspended Trade Stops Across MQL5 Restarts
Summary
This article explains how to preserve the original stop-loss and take-profit levels of open positions when an MQL5 Expert Advisor suspends stops during a news window. It replaces volatile in-memory state with terminal global variables: each saved position has a ticket, stop-loss, and take-profit entry, alongside a count and suspension flag. On initialization, the EA rebuilds its saved state; after the news window, it restores stops and removes the stored values.
The article outlines the save, load, and cleanup functions and describes where they fit into the suspension lifecycle. It says that a restart during an active window can be checked by confirming that saved values return on initialization and that stops are restored after the window ends. The approach depends on a consistent naming scheme and terminal-level storage. Global variables are shared across EA instances, so separate instances need distinct prefixes or identifiers. Loading state does not itself restore stops, because the EA must first determine whether the news window has ended.
Key ideas
- Persist each suspended position's ticket and original stop-loss and take-profit values so they can be recovered after a restart.
- Store a count and suspension flag alongside the per-position data in terminal global variables.
- Reload the saved snapshot during initialization, then restore stops through the normal news-window transition logic.
- Use distinct variable-name prefixes or identifiers when multiple EA instances could otherwise share state.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.