An Expert Advisor can stop trading and still look healthy: the smiley face is on, the terminal is connected, the Experts tab shows no error. You often find out days later, because nothing "happened". This article explains how to tell a quiet market from a stopped EA, and how to be alerted the same day.
Why an EA goes quiet without an error
- Entry conditions never become true after a change in the market, a broker setting or a symbol property (for example a maximum-spread filter that is now always exceeded).
- The terminal restarted. Variables kept in memory are reset. An EA that depends on state built up over earlier ticks can wait for a condition that will never be rebuilt.
- No ticks on the chart symbol. The EA code only runs on a tick, so a symbol with a closed or frozen feed does not run it.
- Trading is blocked by the account, the broker or a disabled "algo trading" button, while the EA stays attached.
Do not rely on trade count alone
"No trade for three days" can be a real signal gap or a failure. Counting trades alone gives false alarms in quiet weeks and misses a dead EA during busy ones. Check two separate things instead: is the EA still running, and is it still taking the trades it should.
1. A heartbeat for "is it still running"
Let the EA write the current time on a timer, and let another program read it. Inside the EA, set a timer in OnInit and update a global variable in OnTimer:
int OnInit(){ EventSetTimer(5); return(INIT_SUCCEEDED); }
void OnTimer(){
GlobalVariableSet("hb_"+(string)AccountInfoInteger(ACCOUNT_LOGIN), (double)TimeLocal());
}
A timer runs even when no tick arrives, so the heartbeat does not depend on market activity. Use local time for the heartbeat, because TimeCurrent() only moves when quotes arrive.
2. A watchdog that checks the heartbeat
Attach a small second EA to another chart in the same terminal, with its own EventSetTimer(10) in OnInit. If the heartbeat is older than a limit you choose, it sends a notification:
void OnTimer(){
string key="hb_"+(string)AccountInfoInteger(ACCOUNT_LOGIN);
if(!GlobalVariableCheck(key) || TimeLocal()-(datetime)GlobalVariableGet(key) > 60)
SendNotification("EA heartbeat is stale on account "+(string)AccountInfoInteger(ACCOUNT_LOGIN));
}
Push notifications need your MetaQuotes ID set in the terminal. For a more reliable setup, send the heartbeat to an outside service or a Telegram bot with WebRequest, so you are alerted even if the whole VPS is down. The URL must be added to the allowed list in the terminal options.
3. A last-trade check for "is it taking trades"
Compare the time of the last deal with the longest quiet period that is normal for your strategy. Select history with HistorySelect, read the newest deal time, and alert only when the gap is longer than your own normal maximum. Set that limit from the EA's real history, not a guess, and apply it only during the hours the EA is allowed to trade.
4. Log the reason, not only the trade
Many "silent" EAs are not broken; they are filtering. Have the EA write one line every hour with its state: last evaluation time, current spread, which filter blocked entry. A log that says "blocked by max spread" for three days tells you the cause at once. Ask for this when you write your brief.
On a VPS
A VPS keeps the terminal running while your PC is off, but a VPS being "up" does not mean the EA is working. That is why the heartbeat belongs inside the EA. See EA VPS setup for the setup itself.
Where we can help
We can add a heartbeat, a last-trade alert and a state log to an existing EA, or include them when we build a new one. See changes to existing code. These checks tell you when something stops; they do not make a strategy profitable, and trading carries risk.
Frequently asked questions
Can I use trade count to detect a stopped EA?
Only as a second check. A quiet market looks the same as a dead EA. A heartbeat tells you the EA is running; a last-trade gap longer than your normal maximum tells you it may not be trading.
Why use a timer instead of OnTick?
OnTick only runs when a quote arrives. On a symbol with no ticks for a while (for example before a late session open) it would show "stopped" when nothing is wrong. A timer keeps running.
Do I need a second terminal for the watchdog?
No. A second chart in the same terminal is enough to start. A separate machine or an outside service gives better coverage, because it also catches a frozen terminal or a failed VPS.