Loading…

Recurring Schedule Parser

An EA or script that needs to do something on a recurring schedule - close all positions every Friday at 21:00, refresh a news filter every 15 minutes, run a weekly report on the 1st of the month - usually ends up with a pile of hand-written if/else conditions checking Hour()/ Day()/DayOfWeek() one field at a time. This library instead parses a compact cron-like text expression once into a CronSchedule struct (five fixed-size boolean allow-arrays, one per field) and answers "when does this next fire" by walking forward minute-by-minute from a given starting time until every field's allow-array agrees. Each of the five fields accepts "*" (any value), "*/n" (every n units, e.g. "*/15" for minutes), or a comma-separated list of exact integers (e.g. "0,30" for hours). This intentionally does not implement full cron syntax - there is no range form ("1-5") and no combined step-on- list form - trading completeness for a parser and data structure small enough to read end to end in one sitting. See NOTES below for the exact supported syntax. Notes and limitations - Supported field syntax is deliberately small: "*", "*/n" (a positive integer step), or a comma-separated list of exact integers. There is NO range syntax ("1-5") and no "list of steps" form - express a range as an explicit comma list instead (e.g. "1,2,3,4,5"). - Day-of-month and day-of-week are combined with AND, not the traditional cron OR-when-both-restricted quirk - an expression naming both a specific day-of-month and a specific weekday only fires when BOTH match in the same run, which is the more intuitive reading for most users but differs from POSIX cron's documented special case. - RecurringScheduleNextFireTime() is a bounded forward scan, not a closed-form calculation - an expression whose fields can never agree (e.g. day 31 restricted to a month that never has 31 days) simply returns 0 once the scan horizon is exhausted, rather than reporting that specific reason. - No seconds field - the finest granularity is one minute, matching MQL4's own TimeCurrent() tick cadence for anything checked once per tick or once per timer interval.

Script · MT4 · v1.0 · Free

About Recurring Schedule Parser

Recurring Schedule Parser is a script for MetaTrader 4. It has 1 setting, such as Expression. MQL source code included.

Files in the download: RecurringScheduleParser.mqh, RecurringScheduleParser.txt, RecurringScheduleParserDemo.mq4.

Settings

SettingDefaultWhat it does
Expression*/15 * * * *Your own expression to test (minute hour day month weekday)

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: News Trading · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria