Advertisement IC Markets

Equity protection: a kill switch for automated trading

Share, develop, and backtest custom MQL4/MQL5 Expert Advisors, Python data-scraping scripts, trading bots, and automated market alert systems.
Post Reply
FXS London Scalper
Posts: 806
Joined: Sun Oct 18, 2026 12:25 pm

Equity protection: a kill switch for automated trading

Post by FXS London Scalper »

An EA running unattended can lose more than planned if markets behave unusually or if a bug causes repeated trades. A kill switch that stops trading when equity falls below a threshold adds a safety layer.

A simple version: at each tick or bar, compare current equity with the starting equity of the day or week. If the drawdown exceeds a limit, close all positions with the EA's magic number and stop opening new ones until manually reset.

A worked example: an EA has a bug in its position counting after a server restart and opens a new trade every minute. A daily equity limit of 3 percent would stop it before the damage grows.

The kill switch should be independent of the trading logic, ideally in a separate EA or script, so that a bug in the strategy code does not disable it.

Testing the switch on demo, by forcing a drawdown, confirms it works.

Do you run any equity protection alongside your EAs?
FXS Official Team | London Session Desk
Recommended broker for automated trading & scalping IC Markets
Amanhasnoname
Posts: 1506
Joined: Fri Oct 30, 2026 9:45 am

Re: Equity protection: a kill switch for automated trading

Post by Amanhasnoname »

I run something like this, and what I learned is that the way you reset it matters as much as the threshold. My first version compared against the starting equity of the day, but after a profitable morning it allowed me to hand back all the gains before it triggered. I now use two limits. One is a daily loss from the start of day at two percent, and the other is a drop of one percent from the day's peak equity, whichever comes first.

I also made the switch do more than close trades. It writes a short line to a file with the time, the equity and the number of open positions it closed, and it sends me a push notification. The first time it fired in real life, I was away from the desk and only knew because of that message.

Be careful with the manual reset step. I made mine require restarting the terminal and deleting a flag file, so it can't be turned back on by accident in a hurry after a bad day.
Post Reply