Discussing the article: "Implementing a Daily Loss Limit and Drawdown Circuit Breaker in MQL5"

 

Check out the new article: Implementing a Daily Loss Limit and Drawdown Circuit Breaker in MQL5.

This article presents a circuit breaker for MQL5 that monitors combined daily P&L (realized plus floating) on every tick and compares it to a configured loss limit. On breach, it closes positions, cancels pending orders, and activates a HALTED state that blocks further order submission in the EA until server‑time midnight. The package provides a chart dashboard, a demo Expert Advisor, a verification script, and notes on extending the halt signal across EAs.

Prop‑firm and other risk‑managed accounts operate under a simple but strict rule: exceed a fixed daily loss and the account is closed or flagged. In practice, many Expert Advisors fail to enforce that rule reliably because they:

  • check the limit only on new bars (not every tick),
  • sum only realized P&L and ignore floating P&L (including swap),
  • have no real gate that prevents new orders once the limit is breached.

The result is an EA that appears compliant in logs yet lets the account slip past the allowable loss in real time. One boundary is fixed from the outset: the module you are about to build operates within a single EA on a single chart. It cannot see or block another EA's orders, and it cannot intercept a manual order placed through the terminal.

This article defines a clear engineering requirement and delivers a reproducible solution: a drop‑in MQL5 module that, on every OnTick(), computes the account's combined daily P&L (realized + floating, including swap) using the broker's server midnight as the reset boundary; compares it to a configured daily loss limit; and, if the limit is breached, immediately closes all open positions, cancels all pending orders, and places the system into a HALTED state until the next server midnight. The module exposes a small, testable public contract (Init(), OnTick(), IsHalted(), GetStatus(), ForceReset()) so you know exactly where and how to integrate it: call IsHalted() before every OrderSend() in your EA. The implementation includes a live chart dashboard and a verification script so the math and trigger logic are verifiable before you deploy.

Architecture of the circuit breaker

Author: Ushana Kevin Iorkumbul