Advertisement IC Markets

EA Risk Controls: Building Safety Into Automated Strategies

Share, develop, and backtest custom MQL4/MQL5 Expert Advisors, Python data-scraping scripts, trading bots, and automated market alert systems.
Post Reply
FXS Prop Desk
Posts: 1793
Joined: Wed Oct 07, 2026 9:52 am

EA Risk Controls: Building Safety Into Automated Strategies

Post by FXS Prop Desk »

An EA without risk controls can damage an account quickly when something goes wrong. A few controls cover most failure scenarios.

Essential controls:
  • Maximum daily loss: stop trading after a set loss.
  • Maximum open positions: prevent runaway order loops.
  • Spread filter: no entries when spread is above a threshold.
  • News filter: pause around high-impact events.
  • Maximum lot size: cap regardless of calculation.
  • Kill switch: a manual or external way to stop the EA immediately.
Testing these controls is as important as testing the strategy: simulate a disconnection, a spread spike, and a calculation error.

It also helps to log every time a control triggers. A spread filter that blocks trades every morning, for example, may indicate that the EA is trading at the wrong time of day.

What safety features do your EAs include?
FXS Official Team | The Idea Lab & Strategy
Recommended broker for automated trading & scalping IC Markets
Shadow Trader
Posts: 5994
Joined: Wed Sep 09, 2026 5:19 pm

Re: EA Risk Controls: Building Safety Into Automated Strategies

Post by Shadow Trader »

Maximum open positions does not catch every runaway loop. I once had an EA open and close the same trade 40 times in two minutes because the exit condition was already true at entry, and it never held more than one position.

So I count orders sent per minute as well, with a hard stop at five. When it trips, the EA disables itself and writes the reason to the journal, and it stays off until I reset it by hand.

The daily loss check should use equity, not closed balance. A limit based only on closed trades lets an open loser run straight past it, which is exactly the case a prop rule punishes.

For the news filter I have the opposite worry. If it relies on a downloaded calendar and the download fails, the safe default is no trading, yet a lot of code I have seen falls through to normal behaviour.

My kill switch is a terminal global variable that every instance checks on each tick. Setting it from one script stops all of them, which beats closing six windows during a fast market.

Spread spikes are easy to test with a custom symbol built from recorded ticks. How do others simulate a disconnection in the tester?
Shadow Trader
Posts: 5994
Joined: Wed Sep 09, 2026 5:19 pm

Re: EA Risk Controls: Building Safety Into Automated Strategies

Post by Shadow Trader »

The daily loss check needs two levels below the firm's limit, not one. When the EA closes everything at the limit itself, slippage on the exit can carry the account through it, and a breach by a few dollars counts the same as a big one.
img_13766_r2.png
img_13766_r2.png (81.26 KiB) Viewed 217 times
The chart lays this out on an invented day against a 4 percent daily limit: new entries stop at minus 3 percent, open trades are closed at minus 3.5, and the forced close fills at minus 3.7. That leaves 0.3 percent spare.

The gap between the levels should come from the worst exit slippage in the logs, not a guess. On a 100k account trading 3 lots of EURUSD, 0.2 percent is about 7 pips of slip, which is plausible in a fast market.

On disconnection, the closest I have got is a demo account on a VPS where I block the terminal with a firewall rule for a few minutes. That shows whether the EA notices stale quotes and refuses to trade on reconnect, which the strategy tester cannot reproduce.

I also compare the last tick time with the server clock and pause entries if the gap passes 30 seconds. Does anyone also keep server side stops on every position in case the terminal itself dies?
Amanhasnoname
Posts: 2442
Joined: Fri Oct 30, 2026 9:45 am

Re: EA Risk Controls: Building Safety Into Automated Strategies

Post by Amanhasnoname »

The point about logging every control trigger is underrated. A control that fires often is telling you something about the strategy, not just protecting it, so it is worth reviewing those logs weekly. A spread filter blocking entries at the same hour every day usually means the trading window should move, and a max positions cap that keeps getting hit often points to a logic bug creating duplicate signals rather than genuine setups.

For testing the controls themselves, the strategy tester can handle some of it if you build deliberate fault injection into the EA behind an input flag. For example, a test mode that pretends the spread is five times wider for a set period, or that returns a bad lot calculation, lets you confirm the guard catches it. Disconnections are harder to simulate in the tester, so many people check those on a demo by simply pulling the network and watching what the EA does on reconnect, especially whether it re-syncs open positions before acting.

One more control worth adding is a sanity check on stops: refuse to send an order with no stop loss or with a stop wider than a fixed maximum. It costs nothing and covers a whole class of calculation errors.
Post Reply