Skip to content
All library documents

Restart-Safe Virtual Stop and Target Recovery with SQLite

Article MQL5 articles

Summary

The article addresses a failure mode in Expert Advisors that keep stop-loss and take-profit levels only in runtime memory: after a terminal shutdown, the EA stops monitoring, while the broker has no knowledge of those virtual levels. It extends an earlier SQLite persistence design so the EA can identify its managed open position after restart, restore its saved trade state, and compare current prices with the stored virtual protection levels before resuming management.

The recovery workflow filters broker positions by chart symbol and magic number, constructs initial protection state after a position opens, and persists that state for later restoration. The article describes closing a position if its virtual stop or target was crossed while the EA was offline and updating its stored status. Its example manages one position at a time and uses controlled test trades rather than a developed entry strategy. It explains an engineering safeguard, but does not provide evidence that the sample EA or its virtual protection is suitable for live trading.

Key ideas

  • Virtual protection held only in memory is lost when the terminal stops.
  • SQLite persistence lets the EA restore saved trade state after restart.
  • Recovery identifies managed positions using their symbol and magic number.
  • The EA should check current prices against restored virtual exits before normal management resumes.
  • The example handles one position at a time and focuses on recovery rather than strategy performance.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.