Loading…

Max Drawdown Circuit Breaker

Balance only moves when a trade closes. Measuring drawdown from peak balance rather than peak equity means this breaker cannot be pushed around by a floating loss that is still open and might recover - it only trips once money has actually been lost, which is the harder and more deliberate trigger a circuit breaker for capital preservation should use. That is a different job from a trailing stop that protects unrealised gains; if that is what you want instead, see Equity Trailing Stop in this catalogue. Peak balance is tracked from the moment this EA is attached, going forward - it does not attempt to reconstruct history from the account's full trade record, which would add real complexity for a number the terminal already tracks correctly from here on. Once the drawdown from that peak reaches InpMaxDrawdownPercent, every open position on the account is closed and the breaker trips. The behaviour after a trip is the part that makes this a breaker rather than a one-off alert: it does not self-reset. It keeps running every tick, and if a position appears while tripped - opened by another EA, by hand, or by a straggling order that had not yet reached the server when the flatten was sent - it is swept closed immediately. Resuming requires the operator to set InpResetTripped to true and re-apply the EA's inputs (open Properties, tick InpResetTripped, click OK). A breaker that quietly resumes trading on its own schedule is not a breaker; it is a snooze button. Notes and limitations - Persistence here covers both peak balance and the tripped flag, unlike Equity Trailing Stop in this catalogue where the equivalent input only restores the peak and arming state, not whether it had tripped. With InpPersistViaGlobalVar on, a restart after a trip stays tripped and keeps sweeping the account closed, which is the safer default for a capital breaker. - Without persistence, any restart forgets both the peak and the tripped state. The new peak balance rebases to whatever balance exists at that moment - which, if the account is still down from the drawdown that just tripped it, is lower than the original peak. The breaker resumes untripped and now allows the same percentage drawdown again measured from this new, lower peak, effectively lowering the bar for a future trip. Treat a restart without persistence as clearing the breaker's memory of the event. - Changing InpResetTripped and re-applying inputs is deliberately different from a full restart: it does not rebase the peak. The breaker only establishes its starting peak the first time it initialises after being attached; toggling an input afterwards resumes from the same tracked peak, which is what makes the manual-reset workflow meaningful rather than a second way to quietly weaken the peak. - Peak balance tracking starts from EA attachment, not from account history - it has no way to know what the account's true all-time peak balance was before that point. - If AutoTrading (or, on MQL5, terminal/account/Expert Advisor trading permission) is off when the breaker trips, it cannot flatten the account. It logs and comments this plainly rather than claiming the account is protected. - This EA only ever closes; it never opens a position on its own, on either platform.

Expert advisor · MT4 · v1.0 · Free

About Max Drawdown Circuit Breaker

Max Drawdown Circuit Breaker is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 7 settings, such as Max drawdown percent, Reset tripped and Persist via global var. MQL source code included.

Files in the download: DrawdownBreaker.ex4, DrawdownBreaker.mq4, DrawdownBreaker.txt.

Settings

SettingDefaultWhat it does
Max drawdown percent10.0Drawdown from peak balance that trips the breaker, in %
Reset trippedfalseSet true and re-apply inputs to manually resume after a trip
Persist via global varfalseSurvive EA/terminal restart using global variables
Slippage pips3Slippage tolerance when flattening, in pips
Max retries5Close attempts per order before giving up
Retry wait ms500Pause between retry attempts, milliseconds
Status log seconds60How often the status/tripped line repeats in the journal

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Trailing Stop & Break-even · Alerts · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria