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: 3303
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: 3303
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: 3303
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:
Post Reply