Building an MQL5 Daily Loss Limit and Drawdown Circuit Breaker
Summary
The article describes an MQL5 module that checks account-wide daily profit and loss on each tick and halts its host Expert Advisor when a configured loss threshold is reached. It calculates realized results from closing deals since broker server midnight, including profit, swap, and commission, then adds floating profit and swap from open positions. On breach, the module closes positions, cancels pending orders, and remains halted until the next server midnight. A dashboard and verification script support monitoring and checking the calculation and trigger behavior.
The design exposes initialization, status, halt-check, and reset methods, with guidance to check the halt state before sending orders. Its scope is limited to the EA instance on one chart: it cannot block manual trades or orders from other EAs unless they cooperate through a shared signal. Server midnight may not match the trader’s local day, and slippage, partial fills, or a pending order filling during cancellation can affect enforcement.
Key ideas
- Daily P&L combines realized closing-deal results with floating profit and swap on open positions.
- The daily calculation window starts at midnight in broker server time.
- A breached loss threshold triggers position closure, pending-order cancellation, and a halt until the next server day.
- The host EA must check the halt state before every order submission.
- The module does not provide account-wide control over manual trades or non-cooperating EAs.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.