Loading…

Heartbeat Mesh Monitor

Running several terminals side by side - one per broker, one per prop account, a VPS mirror of a home setup - creates a blind spot: nothing tells you when one of them has silently crashed, lost its connection, or had its EA removed, while the others keep trading as if everything is fine. This EA gives every instance in the mesh a shared heartbeat. Each instance writes a small file into the terminal's Common\Files folder - visible to every MetaTrader install on the same machine, not just the one that wrote it - containing its own instance id and the time it last wrote the file. On the same timer it scans that shared folder for every other instance's heartbeat file and checks the timestamp written INSIDE each one, not the filesystem's own modify time, against its own current time. A sibling whose embedded timestamp has gone stale past the configured threshold triggers an alert, with a cooldown so one outage does not spam repeat alerts every poll. Reading the embedded timestamp rather than the filesystem's modify date keeps the staleness check meaningful even across machines or accounts with slightly different clocks, since every comparison uses this instance's own notion of "now" against a value that was written by the same convention on the other end. Notes and limitations - Only detects silence, not the cause - a stale sibling could mean a crashed terminal, a removed EA, a lost connection, or simply a machine that was shut down deliberately. It does not distinguish between them. - All instances must share MQL4\Files\ (or MQL5\Files\ on the native MQL5 build)Common - normally automatic on one machine, but instances on genuinely separate machines have no shared FILE_COMMON folder at all and cannot see each other's heartbeats. - A brand-new instance is invisible to the rest of the mesh until its first heartbeat write, and existing instances only notice a new sibling once they scan the folder and find its file for the first time. - Heartbeat files accumulate for every instance id ever seen and are not deleted automatically if an instance is permanently retired - remove its file from MQL4\Files\ (or MQL5\Files\ on the native MQL5 build)Common by hand if it will not return.

Expert advisor · MT4 · v1.0 · Free

About Heartbeat Mesh Monitor

Heartbeat Mesh Monitor is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 5 settings, such as Instance id, File prefix and Heartbeat interval sec. MQL source code included.

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

Settings

SettingDefaultWhat it does
Instance idThis terminal's identity in the mesh; "" auto-generates from account number
File prefixHeartbeatMesh_Shared filename prefix, must match across every instance in the mesh
Heartbeat interval sec20How often this instance rewrites its own heartbeat file
Stale threshold sec90A sibling's heartbeat older than this triggers an alert
Alert cooldown sec300Minimum time between repeat alerts for the same stale sibling

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