Shared State Health Monitor
Several EAs and scripts on the same terminal often coordinate through global variables - a shared "message board" read with GlobalVariableGet and written with GlobalVariableSet. Nothing on the terminal watches that board for problems: a variable an EA was supposed to keep refreshing but stopped touching (a crashed or removed EA, a hung state machine) just sits there silently, and a malformed value (a flag stuck at something other than 0/1, a timestamp variable holding garbage) can quietly break whatever reads it next. This EA audits the whole terminal-wide global-variable set on a timer. A variable is flagged STALE when GlobalVariableTime() shows it has not been touched in longer than InpStaleMinutes. A variable whose name ends in a declared suffix is checked against that suffix's convention: names ending in InpFlagNameSuffix must hold exactly 0 or 1, names ending in InpTimeNameSuffix must hold a plausible Unix timestamp (not zero, not negative, not implausibly far in the future). Findings are logged and alerted once, then go quiet for that variable until it either recovers or a fresh problem appears - so a long-standing known issue does not flood the log every pass. This EA never writes to the global-variable bus itself. It is read-only by design, so it can never be the thing that corrupts whatever it is auditing. Notes and limitations Staleness and malformation checks only cover what is visible through GlobalVariableName/Get/Time - there is no way to know from outside what a variable was SUPPOSED to hold, only what its own naming convention implies. MQL4's global variables are themselves auto-deleted by the terminal after roughly four weeks of no access - a variable this monitor flags as stale for long enough may simply vanish on its own before anyone acts on the finding. The naming-convention checks only apply to the two declared suffixes; a malformed variable using a different naming scheme is invisible to the malformed check (though still covered by the staleness check if it stops being updated).
Expert advisor · MT5 · v1.0 · Free
About Shared State Health Monitor
Shared State Health Monitor is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 7 settings, such as Name prefix filter, Flag name suffix and Time name suffix. MQL source code included.
Files in the download: SharedStateHealthMonitor.ex5, SharedStateHealthMonitor.mq5, SharedStateHealthMonitor.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Name prefix filter | Only audit globals whose name starts with this, blank = all | |
| Flag name suffix | _FLAG | Names ending in this are checked as 0/1 flags |
| Time name suffix | _TIME | Names ending in this are checked as plausible Unix timestamps |
| Stale minutes | 240 | Minutes since last touch before a variable is flagged stale |
| Check minutes | 15 | Minutes between audit passes |
| Alert on findings | true | Pop a terminal Alert() when a new problem is found |
| Log file name | SharedStateHealthMonitor.csv | File written under MQL5\Files\ |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Alerts · MT5 Expert Advisor · MQL5 Source Code