Advertisement IC Markets

A daily loss circuit breaker in the EA, written before I needed it

Share, develop, and backtest custom MQL4/MQL5 Expert Advisors, Python data-scraping scripts, trading bots, and automated market alert systems.
Post Reply
Fairman
Posts: 6955
Joined: Tue Jul 21, 2026 7:11 am
Location: Abuja

A daily loss circuit breaker in the EA, written before I needed it

Post by Fairman »

A daily loss circuit breaker in the EA, written before I needed it

I made a circuit breaker for my EA after reading about someone whose bot kept trading through a bad day. The idea is that if the day's loss reaches a set level, the EA stops opening new trades until the next day.

It checks the realized profit and loss for the current day, plus the floating loss on any open trades, and compares the total to a limit, expressed as a percentage of the balance at the start of the day. If it's reached, it closes everything, if I've set that option, and blocks new entries. At the start of the next trading day it resets.

The most complicated part was defining the day. Which time does the day start, and how does it treat the rollover? I used the same cut off as my prop firm's reset so the two match. I also made it write a clear message to the log and send me a notification when it triggers, so I know it's happened.

It's only triggered once so far, on a news day when the EA took a string of losses. It did what I wanted and I was glad it was there.
It’s Fairman :geek:
Recommended broker for automated trading & scalping IC Markets
Fairman
Posts: 6955
Joined: Tue Jul 21, 2026 7:11 am
Location: Abuja

Re: A daily loss circuit breaker in the EA, written before I needed it

Post by Fairman »

Defining the day is the hardest part, agreed. I use the same reset time as the prop firm or the broker server, depending on the account, and I store the start of day balance in a file so a restart does not reset it. Without that, a restart halfway through a bad day would make the EA think the day just started and give it a fresh limit. That one detail matters more than the limit itself. I test it by forcing a restart on demo in the middle of a losing day and checking the limit is still remembered.
It’s Fairman :geek:
Fairman
Posts: 6955
Joined: Tue Jul 21, 2026 7:11 am
Location: Abuja

Re: A daily loss circuit breaker in the EA, written before I needed it

Post by Fairman »

I would also make the circuit breaker apply to all EAs on the account, not just one. If you run several, each with its own daily limit, together they can lose much more than you intended. I have one small script that watches the total account equity against the start of day figure and sets a flag that all the EAs check before opening anything. It is simple and it means the limit is for the account, not per strategy.
It’s Fairman :geek:
Shadow Trader
Posts: 5594
Joined: Wed Sep 09, 2026 5:19 pm

Re: A daily loss circuit breaker in the EA, written before I needed it

Post by Shadow Trader »

The start of day balance file is the detail that makes or breaks the breaker. Without it, a VPS reboot mid session hands the EA a fresh limit while the account is already down.

I would also log the trigger as its own event, not only as a blocked entry. If the breaker fires three times in a month, that is a strategy problem, not a safety feature doing its job.

Floating loss must count, as you said. Counting only closed P and L lets a bag of open losers sit under the limit until they all stop out at once and blow past it.

Matching the prop firm reset time is right for funded accounts. On a personal account I would still pick one fixed server hour and never mix broker midnight with local midnight, because mixed clocks create quiet double limits.

Has anyone stress tested the breaker by forcing open losers plus a restart on demo? Did the flag survive both cleanly?
Shadow Trader
Posts: 5594
Joined: Wed Sep 09, 2026 5:19 pm

Re: A daily loss circuit breaker in the EA, written before I needed it

Post by Shadow Trader »

Floating loss still understates what the breaker can be hit for. The number that matters before a new entry is realised loss, plus the full risk to the stops on everything open, plus the risk of the trade being considered.

Say the limit is 300 on a 10,000 start of day balance, realised loss is 200, and one open trade has 100 to its stop while showing only 40 floating. A new 100 risk trade looks fine against 240, but the worst case is 400, so the check should block it.

Some prop firms also take the daily base as whichever is higher at the reset, balance or equity. Hold a 400 winner through it on a 10,000 account and a 5 percent limit counts from 10,400, so the floor is 9,880 rather than 9,500.

An EA that only reads balance at the reset will think it has 380 more room than it really does. Reading equity at the reset and storing the higher figure in the same file as the start of day balance keeps the two in step.

Does the breaker here close open trades when it fires, or only block new ones? Closing everything in the same fast tape that caused the losses can add a slippage cost on top.
FXS Prop Desk
Posts: 1689
Joined: Wed Oct 07, 2026 9:52 am

Re: A daily loss circuit breaker in the EA, written before I needed it

Post by FXS Prop Desk »

Including floating losses in the check is important, since a large open loss can push the account past the limit without any closed trades.

It might also be useful to make the breaker close all open positions when the limit is reached, not just stop new trades. Otherwise, open positions can continue to lose after the limit is hit, which is exactly the situation the breaker is designed to prevent.
FXS Official Team | The Idea Lab & Strategy
Shadow Trader
Posts: 5594
Joined: Wed Sep 09, 2026 5:19 pm

Re: A daily loss circuit breaker in the EA, written before I needed it

Post by Shadow Trader »

Automated systems don't get tired or emotional, but they can fail in new ways. A broken data feed, a changed market regime, a logic error. The danger is that a bot keeps trading through a problem at full speed.

A circuit breaker limits the damage. The simplest version counts consecutive losses and halts trading after a set number, say six. A second layer limits daily loss in currency or percent. A third watches for abnormal behaviour: too many trades in an hour, spreads far above normal, or repeated order rejections.

When a breaker trips, the system should stop opening new trades, send an alert, and wait for manual review. Automatic restarts defeat the point.

The thresholds should come from the strategy's history. If the worst losing run in testing was eight, a breaker at six will trip occasionally in normal operation, which is fine, while one at twenty offers little protection.

What circuit breakers are built into automated systems, and has one ever saved the day?
Post Reply