Loading…

Persistent Order Scheduler

A trader who knows in advance they want an order sent Thursday at the London open, days from now, has no built-in way to arrange that in MetaTrader 4 beyond leaving a terminal open and remembering. If the terminal restarts - a Windows update, a power blip, a VPS reboot - an in-memory schedule is gone and, worse, there is no record of whether the order already fired before the restart. This EA holds up to five independent schedule slots, each describing an order type, lot size, fire date/time, stop-loss/take-profit distance in pips, a maximum acceptable spread, and a grace window. The fired/skipped state of every slot is written to a CSV file under MQL4\Files immediately after each state change, so a restart re-reads that file on OnInit and never re-sends an order that already fired, and never silently forgets one that is still pending. The naive version of a scheduler just fires OrderSend() the instant the clock reaches the target time. This one revalidates first: it refuses to fire while trading is disabled, refuses while the spread exceeds the slot's configured maximum, re-normalises the lot size against the broker's current MODE_MINLOT/MODE_MAXLOT/MODE_LOTSTEP (which can differ from what was true when the schedule was written days earlier), and checks the computed stop distance against the broker's live MODE_STOPLEVEL before sending. If none of those hold within the slot's grace window, the slot is marked skipped rather than fired incorrectly or left silently retrying forever. Notes and limitations Terminal time, not broker server time, is used for the fire comparison (TimeCurrent() in MQL4 is server time as reported by the connected account, so this matches whatever the terminal shows) - confirm this matches your intended trading-session clock before relying on it. The state file is keyed by symbol and magic number. Changing InpMagic on an existing schedule starts a fresh, unfired state file rather than resuming the old one - this is intentional so two independently configured schedules never share state by accident, but it also means changing the magic loses "already fired" history for the old slots. A slot that never meets its revalidation conditions before its grace window expires is marked SKIPPED and never retried again in that run; edit the input and reload the EA (or clear the state file) to reschedule it. Only market orders (BUY/SELL) are supported - there is no pending-order type in this version. This EA does not manage or trail positions after they open; it only sends the initial order.

Expert advisor · MT5 · v1.0 · Free

About Persistent Order Scheduler

Persistent Order Scheduler is an expert advisor (trading robot) for MetaTrader 5. It has 7 settings, such as Slot1, Slot2 and Slot3. MQL source code included.

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

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

Settings

SettingDefaultWhat it does
Slot1Slot 1: type;lots;YYYY.MM.DD HH:MM;slPips;tpPips;maxSpreadPips;graceMinutes
Slot2Slot 2: same format, blank = disabled
Slot3Slot 3: same format, blank = disabled
Slot4Slot 4: same format, blank = disabled
Slot5Slot 5: same format, blank = disabled
Magic45300Magic number applied to every order this EA sends
Slippage pips3Slippage tolerance in pips at fire time

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: Trading Sessions · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria