Deadline Manager
Most EAs that need "do X at time Y" logic hand-roll a single datetime variable and an if-check, which stops working the moment there is more than one deadline to track, or the terminal restarts and the deadline is forgotten entirely. DeadlineManager gives every deadline a name, and tracks any number of them side by side. A deadline is either one-shot (fires once, then goes inactive) or recurring (reschedules itself forward by a fixed interval each time it fires, catching up by whole intervals rather than firing a burst of stale events if the EA was offline for a while). DmCheckDue() is a poll, called once per tick or timer event, that returns the names which just came due. MQL4 has no function pointers, so this is deliberately NOT a callback registry in the C#/JavaScript sense - there is no way to hand the library a function reference to invoke later. DmCheckDue() hands back a plain string array of fired names instead, and the caller's own if/switch on that name is the dispatch. That is the honest MQL4 shape of "callback", not a workaround for a missing feature. DmSaveState()/DmLoadState() persist the whole set to named global variables (GlobalVariableSet/Get), keyed by a caller-chosen prefix. Since GlobalVariableSet only stores a double, each deadline's name is carried in the global variable's own NAME rather than its value, and reloading enumerates GlobalVariablesTotal()/GlobalVariableName() to rebuild the set - so deadline names must avoid the '|' character, which is used as the internal field separator. Notes and limitations - No function-pointer callbacks - DmCheckDue() is poll-based, see the full description above. Call it at least as often as your shortest recurring interval, or it will simply be caught up on the next poll after the fact rather than missed. - Deadline names must not contain '|' - it is the internal separator used both for the persisted global-variable naming scheme. - GlobalVariableSet-created variables are auto-deleted by the terminal after roughly four weeks with no access. A deadline manager that saves once and is not reloaded/re-saved again for over a month can lose its persisted state silently - call DmSaveState periodically, not only on shutdown, if long dormancy is expected. - DmRemove() only affects memory; call DmSaveState() again afterwards if the removal should also survive a restart. - All lookups are a linear scan over the in-memory array - fine for the tens of deadlines a typical EA/panel needs, not designed for thousands of named deadlines in one set.
Script · MT4 · v1.0 · Free
About Deadline Manager
Deadline Manager is a script for MetaTrader 4. It has 1 setting, such as Persist prefix. MQL source code included.
Files in the download: DeadlineManager.mqh, DeadlineManager.txt, DeadlineManagerDemo.mq4.
Settings
| Setting | Default | What it does |
|---|---|---|
| Persist prefix | DmDemo | Prefix used for the global-variable persistence test |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: MT4 Script · MQL4 Source Code