Loading…

Warm Restart Continuity Framework

The MQL4 order pool itself already survives a restart - it lives on the broker's server, not in the terminal - so "adopting" an open trade after a restart is not about re-discovering that it exists; OrdersTotal() already shows it. What actually breaks on a naive restart is the EA's own in-memory bookkeeping about that trade: a trailing-stop watermark that had climbed 300 points in the position's favour silently resets to the entry price the moment the EA reinitialises, and a "trade once per day" guard tracked only as a local bool resets to "never traded" and can fire a second entry on the same day. This template fixes both by writing a small state file (last-trade-day guard plus one row per tracked ticket's trailing watermark) on a timer and on OnDeinit, then on OnInit loading it and reconciling it against the live order pool before anything else runs: a loaded ticket still open is adopted with its watermark preserved exactly; a loaded ticket no longer open is looked up in history and its outcome logged, then dropped; a live order under this EA's own magic number with no loaded state at all (opened just before an unclean crash, after the last save) is adopted with its watermark initialised from the current price rather than losing the position's progress or its stop level. The trailing-stop and once-per-day rules are deliberately simple so the persistence-and-reconciliation pattern is what stands out; wire in your own strategy's state on top of the same OnInit-time reconcile step. Notes and limitations The demo strategy (one moving-average-direction entry per calendar day, trailed once in profit) is a vehicle for the continuity pattern, not a tuned system. The tracked-ticket table is a fixed-size array (200 slots), not a dynamic one, per house style's guidance against dynamic-array struct members - a template tracking more than 200 simultaneous positions would need that constant raised and recompiled. State is saved on a timer and on OnDeinit, not on every tick, so a hard crash can still lose up to InpSaveIntervalSec seconds of trailing progress; the OnInit reconcile step recovers gracefully from that gap by re-adopting from the current price rather than failing.

Expert advisor · MT5 · v1.0 · Free

About Warm Restart Continuity Framework

Warm Restart Continuity Framework is an expert advisor (trading robot) for MetaTrader 5 based on Moving Average. It moves the stop loss behind price (trailing stop / break-even) and has a news filter. It has 7 settings, such as State file, Trade symbol and Lots. MQL source code included.

Files in the download: WarmRestartContinuity.ex5, WarmRestartContinuity.mq5, WarmRestartContinuity.txt.

Trading robots can lose money. Check every setting and test on a demo account before using real funds.

Settings

SettingDefaultWhat it does
State fileWarmRestartContinuity_state.csvFile under MQL5\Files\
Trade symbolSymbol to trade, blank = current chart symbol
Lots0.01Lot size for the demo daily entry
Magic48501Magic number for this EA's own orders
Trail start points200Points in profit before the trailing watermark starts tightening the stop
Trail step points100Trailing distance behind the watermark, points
Save interval sec15How often OnTimer persists state, seconds

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Experts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: Trailing Stop & Break-even · News Trading · Moving Average · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria