Connection Watchdog
An EA that manages open positions is only as good as its ability to run, and it cannot run without a connection - a dropped connection during an unattended session is exactly the moment a trader most needs to be told about it, and least likely to notice on their own. This EA does one job: watch IsConnected() and say, loudly and with a timestamp, when it changes. The detection loop runs on OnTimer, not OnTick. OnTick simply does not fire while there is no live connection - there is nothing to tick with - so an EA that only checks the connection state inside OnTick can never observe the moment it actually drops, only notice in hindsight once ticks resume. Timers keep firing regardless of connection state, which is the only way in MQL4 to catch the disconnect itself. This EA never touches a trade. There is nothing a program can usefully do about a lost connection except tell the trader as clearly and as fast as possible - Alert, an optional push notification, an optional email, and a CSV record once the outage is over and its duration is known. Notes and limitations - Outage duration is measured with TimeLocal() (wall-clock time), not TimeCurrent() - the server-time clock this terminal tracks stops advancing the moment the connection drops, so it cannot be used to measure the outage that just happened. - An outage is only written to the CSV log once it resolves, because the duration is not known until then. An outage that never resolves because the terminal itself is closed is never logged - nothing can run to log it once the terminal is gone. - This EA only observes and reports. It never opens, closes or modifies a trade, and it cannot do anything to restore the connection itself.
Expert advisor · MT5 · v1.0 · Free
About Connection Watchdog
Connection Watchdog 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 Check interval sec, Min downtime to log sec and Alert on disconnect. MQL source code included.
Files in the download: ConnectionWatchdog.ex5, ConnectionWatchdog.mq5, ConnectionWatchdog.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Check interval sec | 1 | Seconds between connection checks |
| Min downtime to log sec | 2 | Outages shorter than this are not logged, to skip micro-blips |
| Alert on disconnect | true | Popup alert the moment a disconnect is detected |
| Alert on reconnect | true | Popup alert when the connection returns |
| Send push on disconnect | false | Send a mobile push notification on disconnect (needs MetaQuotes ID set up) |
| Send email on disconnect | false | Send an email on disconnect (needs SMTP set up in terminal options) |
| Csv file name | ConnectionWatchdog_Log.csv | Outage log, in 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 · Trading Sessions · MT5 Expert Advisor · MQL5 Source Code