Why Every EA Needs a Kill Switch
An expert advisor will keep doing exactly what it was coded to do, even when that’s the wrong thing. A bug, a broken data feed or a market the strategy was never built for can turn a working EA into one that loses money quickly, often while you’re asleep or away from the screen.
This article explains why every EA needs a kill switch, what should trigger it and how to build one in MQL5 so it actually stops the damage.
What a Kill Switch Is
A kill switch is logic that stops the EA completely when something goes wrong. It closes or freezes open positions, cancels pending orders and blocks any new trades until you have looked at what happened and decided to restart.
It’s different from a stop loss, which protects one trade. A kill switch protects the whole account from the EA itself, including the failures you didn’t think to plan for.
Why Stop Losses Aren’t Enough
Stop losses assume the EA is working properly. They don’t help if a bug opens the same trade twenty times, if the EA keeps re-entering after every stop in a market that has changed character, or if a stop slips badly in a fast move. Each trade can look fine on its own while the account bleeds.
Prop accounts make this more urgent. Breaching a daily or maximum loss limit ends the account, so the time between something going wrong and the limit being hit can be very short.
What Should Trigger It
Loss limits. Stop trading when the day’s loss from the start of the trading day reaches a set threshold, and stop the EA entirely if equity falls a set amount from its peak. Both should sit well inside the firm’s limits.
Losing streaks. A run of losses far longer than anything in the backtest is a sign that conditions or the code have changed.
Unusual behaviour. More trades in an hour than the strategy ever places, position sizes above the expected maximum or more open positions than the design allows all point to a bug.
Bad conditions. Spreads far wider than normal, repeated rejected orders or a lost connection to the server are reasons to pause rather than keep trading blind.
Build It Into the Code
Check the triggers on every tick and also in OnTimer, so the kill switch still runs in quiet markets when ticks are slow. Use AccountInfoDouble with ACCOUNT_EQUITY for live equity rather than balance, so floating losses count.
When a trigger fires, close the EA’s positions by magic number, delete its pending orders and set a flag that blocks new entries. ExpertRemove can then unload the EA from the chart entirely if you want a hard stop.
Make It Survive a Restart
A kill switch that resets when the terminal restarts isn’t much protection. If the VPS reboots overnight, the EA could start trading again as if nothing had happened.
Store the kill state somewhere that persists. A terminal global variable set with GlobalVariableSet survives restarts, and the EA can check it in OnInit and refuse to trade until you clear it manually. A small file in the terminal’s files folder works too.
Add a Manual Switch and Alerts
You should also be able to stop the EA yourself. The Algo Trading button in MT5 disables automated trading for every EA in the terminal at once, which is useful in an emergency. An input or a global variable that tells the EA to flatten and stop gives you finer control.
Have the EA tell you when the kill switch fires. SendNotification sends a push message to the MT5 app on your phone, so you find out straight away rather than the next time you check the account.
Test the Kill Switch Too
Untested safety code can fail exactly when you need it. Force each trigger on a demo account by lowering the thresholds, and check that positions close, pending orders are removed, the flag survives a restart and the alert arrives. A kill switch that has never fired is an assumption, not a protection.
Kill Switches on a TTT Markets Account
Our daily and maximum loss limits are measured on real-time equity, including floating losses, commissions and swap, and the daily loss counter resets at midnight server time. Base your kill switch on equity and the same server time, and set the daily trigger well inside the limit, such as 2% against our 4% daily limit.
Trades must be held for at least two minutes, so factor that into the shutdown logic. Blocking new entries the moment a trigger fires is always safe. Expert advisors are allowed on our accounts with no approval process, and you can test your kill switch on a free MT5 demo account with no expiry.
Conclusion – Why Every EA Needs a Kill Switch
Every EA will eventually face a situation it wasn’t built for. A kill switch makes sure that moment costs a little rather than everything. Trigger it on loss limits, losing streaks, abnormal behaviour and bad conditions, run the checks on a timer as well as on ticks, make the stop survive restarts, add a manual override and alerts, and test it until you know it works.
FAQ – Why Every EA Needs a Kill Switch
1. Isn’t a stop loss on every trade enough?
No. Stop losses protect individual trades but not the account from a malfunctioning EA, repeated entries or slipped stops in fast markets.
2. Where should I set my daily kill switch?
Well inside your firm’s limit. Many traders set it at around half the daily allowance, so open trades have room to close without crossing the line.
3. How do I stop the EA restarting after a kill?
Store the kill state in a terminal global variable or a file, check it in OnInit and only resume trading once you clear it yourself.
We have helped thousands of traders reach funding at TTT Markets from account sizes of $5k upwards to $500k. Check out our programs.
Additional resources:
support@tttmarkets.com
WhatsApp Support →