Loading…

Timer And Scheduler

EventSetTimer gives a program exactly one timer, firing everything on a single shared rate. Most EAs actually need several independent cadences running at once - check the spread on every tick, refresh a dashboard panel every five seconds, re-read a news calendar once a day at a fixed time - and the usual result is a pile of "static datetime lastCheck" variables and an if-block for each one, scattered through OnTick. This header replaces that pattern with named tasks. Register each one once - SchedulerAddInterval, SchedulerAddOnce, or SchedulerAddDaily - then call SchedulerPoll from wherever the program already runs and read back which task names came due. Task state lives in the header, keyed by the name you chose. The current time is passed in explicitly rather than read internally from TimeCurrent(). That is deliberate: it means the same code can be driven by a synthetic clock in a test or a demo (no Sleep(), no waiting), and it means an EA chooses TimeCurrent() or TimeLocal() consistently across every task instead of the header silently picking one. Interval tasks that missed several firings - the terminal was paused, a backtest jumped forward, SchedulerPoll simply was not called for a while - are fast-forwarded to the next due time rather than firing once per missed interval. Without that, resuming after a gap produces a burst of catch-up firings for every task, all in the same poll, which is very rarely what a caller actually wants and is a common source of a "why did my EA just do twelve things at once" bug report. Notes and limitations - Not thread-safe in the sense of concurrent access - MQL4 and MQL5 programs are both single-threaded per chart, so this is not a practical concern, but it means one program's scheduler state is entirely its own; nothing is shared across charts or programs. - Daily scheduling has no time zone or DST awareness on either platform - "daily at 08:00" means the clock value you pass in, typically broker server time, crosses 08:00 in whatever offset that clock already carries. - SchedulerPoll must actually be called for anything to fire. A scheduler that is registered but never polled - for example inside a script that returns immediately - never runs its tasks; this header is not a background thread. - Capacity grows dynamically with ArrayResize as tasks are added; there is no fixed task limit to configure.

Script · MT4 · v1.0 · Free

About Timer And Scheduler

Timer And Scheduler is a script for MetaTrader 4. It has 1 setting, such as Simulated seconds. MQL source code included.

Files in the download: Scheduler.mqh, Scheduler.txt, SchedulerDemo.mq4.

Settings

SettingDefaultWhat it does
Simulated seconds30How many simulated seconds to step through

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

MQL4 & MQL5 scripts · PolyMaria