Loading…

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 · MT4 · v1.0 · Free

About Shared State Health Monitor

Shared State Health Monitor 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 Name prefix filter, Flag name suffix and Time name suffix. MQL source code included.

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

Settings

SettingDefaultWhat it does
Name prefix filterOnly audit globals whose name starts with this, blank = all
Flag name suffix_FLAGNames ending in this are checked as 0/1 flags
Time name suffix_TIMENames ending in this are checked as plausible Unix timestamps
Stale minutes240Minutes since last touch before a variable is flagged stale
Check minutes15Minutes between audit passes
Alert on findingstruePop a terminal Alert() when a new problem is found
Log file nameSharedStateHealthMonitor.csvFile written under MQL4\Files\

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