Loading…

Calendar Driven Automation

Building a scheduler inside every EA that needs one is wasted effort when every phone, desktop, and web calendar already knows how to store "do this, at this time" and export it as a standard .ics file. This EA reads one .ics file from MQL4\Files\ (or MQL5\Files\ on the native MQL5 build), parses each VEVENT block's UID, DTSTART and SUMMARY, and treats SUMMARY as a command from a small closed vocabulary: CLOSEALL/FLATTEN, DISABLE_TRADING, ENABLE_TRADING, and ALERT <text>. Anything else in SUMMARY is logged and ignored, never interpreted - a calendar entry can never make this EA do something outside that fixed list, which is the point: scheduling power without turning a text field into an arbitrary command interpreter. The parser resolves ICS "line folding" (a continuation line starting with a single space) before reading properties, so a long SUMMARY wrapped across lines is not misread as two separate properties. Each event fires once: a fired flag keyed on UID survives file reloads, so editing unrelated future events in the same file does not re-trigger something that has already run. An event whose start time has already passed by more than InpFireToleranceSec when first seen (the terminal was closed over it, for example) is marked fired without being executed, rather than firing a stale action arbitrarily late. CLOSEALL/FLATTEN always run even while DISABLE_TRADING is in effect - a halt is meant to stop new exposure, not block an explicit scheduled flatten. Notes and limitations - The command vocabulary is deliberately small (five forms). This is a scheduler for safe, reviewable actions, not a general remote-control channel - it will never grow into "run arbitrary MQL" without a rewrite, by design. - DTSTART values ending in "Z" (UTC) are read as server time directly, without a timezone conversion - the terminal has no reliable source for the broker server's UTC offset. If the broker server is not UTC, adjust event times in the calendar app to compensate, or use a floating/local DTSTART instead of a UTC one. - Recurring events (RRULE) are not expanded - only the single DTSTART in each VEVENT block is read. A recurring meeting exported by a calendar app typically expands into one VEVENT per occurrence anyway in most exporters' output, but this is worth checking against your specific calendar app before relying on it. - No trading action here opens a position; DISABLE_TRADING only sets an internal flag this EA itself checks before acting on future events. It has no effect on other EAs or on manual trading. - File I/O is sandboxed to MQL4\Files\ (or MQL5\Files\ on the native MQL5 build), per platform rules - the ICS file must be placed there manually or by another process with access to that folder.

Expert advisor · MT4 · v1.0 · Free

About Calendar Driven Automation

Calendar Driven Automation is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 7 settings, such as Calendar file, Symbol filter and Magic filter. MQL source code included.

Files in the download: CalendarDrivenAutomation.ex4, CalendarDrivenAutomation.mq4, CalendarDrivenAutomation.txt.

Settings

SettingDefaultWhat it does
Calendar filetrading_calendar.icsICS file in MQL4\Files\ to read
Symbol filterRestrict CLOSEALL/FLATTEN to this symbol; blank = every symbol
Magic filter0Restrict actions to this magic number; 0 = every magic
Reload seconds60How often to re-read the ICS file for edits/new events
Fire tolerance sec90An event's start time must be within this many seconds of "now" to fire
Slippage points30Slippage allowed on CLOSEALL market closes
Verbose logtruePrint every parsed event at load time

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Alerts · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria