Three Stage ATR Ratchet Manager MT5
- 유틸리티
-
Anthony Cooke
Quantitative Systems Architect and C++, Python, MQL5, MQL4, and Pine Script developer specializing in non-repainting mathematical indicators, Expert Advisors, and statistical strategy audits. I combine industrial quality-control engineering and Applied Mathematics with multi-physics market modeling - 버전: 1.1
- 활성화: 5
OVERVIEW AND INSTITUTIONAL RISK ORIGIN
The Three Stage ATR Ratchet Manager is an institutional trade-management and equity-governance Expert Advisor engineered from Quantitative Risk Management and Asymmetric Stop-Loss Control Theory. Professional proprietary trading desks and systematic risk officers do not manage trades with static pip stops or fixed lot sizes because market volatility expands and contracts constantly across assets and sessions. A 20-pip stop that works on a calm EURUSD morning session is instantly swept during a volatile Gold (XAUUSD) expansion.
This utility Expert Advisor automates three critical risk functions inside one lightweight, transparent cockpit:
1. Volatility-normalized 3-Stage High-Water-Mark (HWM) ATR stop-loss ratcheting for your manual trades or positions opened by other Expert Advisors.
2. Automated daily and total equity drawdown circuit breakers aligned with strict proprietary trading firm drawdown rules and funded account risk governance.
3. Dynamic drawdown-cushion lot sizing that automatically scales trade exposure across different symbols and tapers risk smoothly when account equity dips.
By default, automated live trade entries are turned OFF (InpEnableAutoEntry = false), meaning the Expert Advisor acts purely as a silent trade manager and equity guardian without opening unrequested live trades.
HOW THE 3-STAGE HIGH-WATER-MARK ATR RATCHET WORKS (WITH CLEAR CALCULATION EXAMPLE)
All stop-loss distances are calculated using strictly causal closed-bar Average True Range on your chosen reference timeframe (default H1, 14-bar ATR). The Expert Advisor tracks each open position's tick-by-tick High-Water-Mark (the most favorable price reached since entry) and steps the Stop Loss strictly forward in one direction—never widening risk backward—while honoring broker stop levels, freeze levels, and symbol tick sizes.
How the Four Ratchet Stages Progress:
- Stage 0 (S0 INITIAL SL): If you open a trade without a Stop Loss and InpAutoAttachInitSL is enabled, the EA immediately attaches a protective hard stop at 2.00x ATR from entry.
- Stage 1 (S1 BREAKEVEN): Once unrealized peak profit reaches +2.00x ATR, the EA snaps the Stop Loss to Entry + 0.05x ATR, eliminating trade risk and covering typical transaction friction.
- Stage 2 (S2 PROFIT LOCK): Once peak profit reaches +3.00x ATR, the EA ratchets the Stop Loss forward to lock in +1.50x ATR of banked profit.
- Stage 3 (S3 PEAK TRAIL): Once peak profit reaches +4.50x ATR, the EA activates dynamic High-Water-Mark trailing, keeping the Stop Loss continuously 2.00x ATR behind the highest favorable price reached.
Simple Numerical Example (Buy Position on EURUSD H1 where ATR = 100 points / 10 pips):
- Entry Price: 1.10000
- S0 Initial SL (2.0x ATR): Placed at 1.09800 (-200 points risk) if no SL was set manually.
- S1 Breakeven (Trigger at +2.0x ATR = 1.10200): Stop Loss snaps to 1.10005 (+5 points above entry).
- S2 Profit Lock (Trigger at +3.0x ATR = 1.10300): Stop Loss ratchets to 1.10150 (+150 points locked profit).
- S3 Peak Trail (Trigger at +4.5x ATR = 1.10450): If price climbs to 1.10600 (+600 points peak), Stop Loss trails smoothly to 1.10400 (+400 points locked). If price pulls back slightly, the Stop Loss holds firm at 1.10400 and never moves backward.
EQUITY CIRCUIT BREAKERS AND DRAWDOWN-CUSHION LOT SCALING
Daily and Total Drawdown Governance:
- Daily Equity Baseline: Automatically resets at broker midnight using the higher of Account Balance or Account Equity, matching standard institutional daily loss accounting.
- Hard Daily Drawdown Breaker (Default 4.00%): If intraday equity drops by InpMaxDailyDDPct from the daily baseline, the EA automatically closes all managed positions, switches HUD status to DAILY DD LOCK, and blocks further automated entries until the next broker day rollover.
- Hard Total Drawdown Breaker (Default 8.50%): Compares live equity against your account starting baseline (InpInitialBalance, or automatic initial equity/balance when set to 0.0). If breached, closes all managed positions and engages TOTAL DD LOCK.
How Drawdown-Cushion Lot Scaling Calculates Position Size:
Rather than trading full size all the way into a daily limit, the EA computes a live Cushion Multiplier between 100% and 25%:
- Below InpCushionStartDD (default 1.50% drawdown): Cushion stays at 100% of your base risk (InpBaseRiskPct, default 1.00% of equity).
- Between 1.50% and the Daily or Total DD limit: The cushion scales smoothly downward in a straight line toward a 25% minimum floor, automatically reducing lot size as drawdown deepens.
- Cross-Asset Volatility Normalization and Margin Check: Calculated lot size equals (Equity x Base Risk % x Cushion Multiplier) divided by the exact dollar loss of 1 lot across your Initial SL distance (InpInitSL_ATR x ATR), rounded strictly down to the broker volume step and verified against available free margin.
Note on Cross-Asset Gallery Screenshots:
Our screenshot gallery displays the live cockpit across both EURUSD H1 (approximately 100-point ATR, scaling to 0.49 lot) and XAUUSD H1 (approximately 2000+ point ATR, automatically scaling down to 0.02 lot) across STANDBY, S0, S1, S2, and S3 states. This demonstrates how the engine keeps dollar risk consistent across wildly different asset volatilities automatically.
INSTANT-RENDER COCKPIT HUD AND VISUAL GUIDE
The dark upper-left cockpit panel (DodgerBlue border, Gold header) renders immediately upon attaching the EA to your chart, even during weekends or market rollover pauses when no ticks are arriving:
- STATUS: ACTIVE GUARDIAN (Lime), DAILY DD LOCK (OrangeRed), or TOTAL DD LOCK (OrangeRed).
- DAILY DD: Current daily equity drawdown percentage versus your hard daily limit.
- TOTAL DD: Current total equity drawdown percentage versus your hard total limit.
- CUSHION and NEXT LOT: Live risk cushion percentage (100% down to 25%) alongside the exact pre-calculated volatility-adjusted lot size for your next trade on that chart.
- ATR and POS: Live closed-bar ATR reading in broker points plus the current count of open managed positions.
- RATCHET: Live highest active management stage across open trades (STANDBY, S0 INITIAL SL, S1 BREAKEVEN, S2 PROFIT LOCK, or S3 PEAK TRAIL).
- STAGES: Quick reference readout of your configured stage trigger multiples (default 2.0x | 3.0x | 4.5x ATR).
HOW TO USE IN LIVE TRADING AND STRATEGY TESTER
Live Manual Trade or Multi-EA Management (Default Mode):
1. Attach Three Stage ATR Ratchet Manager to your chart with Algorithmic Trading enabled.
2. Keep InpEnableAutoEntry = false so the EA never opens live trades on its own.
3. Leave InpMagicNumber = 0 to manage all manual trades and EA positions on the current symbol, or set a specific Magic Number to supervise one dedicated strategy. Set InpManageAllSymbols = true if you want one single chart instance to guard and ratchet every symbol across your account.
4. Read the pre-calculated NEXT LOT value directly off the Cockpit HUD before placing your manual trade so your position size matches your exact equity risk and drawdown cushion.
Testing in Strategy Tester Visual Mode:
InpTesterDemoTrades is set to true by default (strictly active inside Strategy Tester only, never on live or demo forward charts). Launch Visual Mode on EURUSD H1 or XAUUSD H1 to watch the EA execute simple causal 20-bar breakout demo entries and step live positions through S0 Initial SL, S1 Breakeven, S2 Profit Lock, and S3 Peak Trail while updating the cockpit telemetry in real time.
COMPLETE INPUT PARAMETERS (GROUPED BY FUNCTION)
Trade Scope and ATR Engine:
- InpMagicNumber (Default: 0): Magic Number filter (0 manages all manual and EA positions; enter a specific number to target one EA).
- InpManageAllSymbols (Default: false): False manages only the chart symbol; true manages all open symbols across the entire account.
- InpATRTimeframe (Default: PERIOD_H1) and InpATRPeriod (Default: 14): Reference timeframe and bar period for closed-bar ATR calculations.
3-Stage ATR Ratchet Controls:
- InpAutoAttachInitSL (Default: true) and InpInitSL_ATR (Default: 2.00): Automatically sets a protective hard Stop Loss if a managed trade has no SL.
- InpStage1TriggerATR (Default: 2.00) and InpStage1LockATR (Default: 0.05): Profit trigger and Stop Loss offset for Stage 1 Breakeven.
- InpStage2TriggerATR (Default: 3.00) and InpStage2LockATR (Default: 1.50): Profit trigger and banked Stop Loss level for Stage 2 Profit Lock.
- InpStage3TriggerATR (Default: 4.50) and InpStage3TrailATR (Default: 2.00): Profit trigger and High-Water-Mark trailing distance for Stage 3 Peak Trail.
Equity Protection and Risk Scaling:
- InpBaseRiskPct (Default: 1.00): Base percentage of account equity risked per trade for NEXT LOT calculation and optional auto entries.
- InpMaxDailyDDPct (Default: 4.00): Hard daily drawdown circuit breaker percentage (set slightly below your account's 5.0% daily rule to leave a safety buffer).
- InpMaxTotalDDPct (Default: 8.50): Hard total drawdown circuit breaker percentage (set comfortably below a 10.0% maximum loss rule).
- InpCushionStartDD (Default: 1.50): Drawdown percentage where automatic risk tapering begins.
- InpInitialBalance (Default: 0.0): Reference starting account balance for Total DD calculation (0.0 automatically captures balance/equity at initialization).
Time Governance, Mode, and Display:
- InpUseTimeStop (Default: false) and InpMaxHoldHours (Default: 36): Optional maximum holding time that closes stagnant trades automatically.
- InpUseSessionFlatten (Default: false) and InpFlattenHour (Default: 21): Optional daily broker-hour cutoff to flatten all managed trades before rollover or weekend gaps.
- InpEnableAutoEntry (Default: false): Enables optional built-in 20-bar closed-candle ATR breakout entries on live accounts (keep false for pure trade management).
- InpTesterDemoTrades (Default: true): Runs demo breakout entries inside Strategy Tester only so you can inspect ratchet behavior visually.
- InpShowDashboard (Default: true): Toggles the upper-left Cockpit HUD (automatically disabled during optimization runs).
HOW TO CALIBRATE AND MODIFY FOR YOUR ACCOUNT AND TRADING STYLE
Every multiple, timeframe, and equity limit is open for customization so you can match your exact strategy and funded account rules:
- Fast Intraday Scalping (M5 to M15): Switch InpATRTimeframe to PERIOD_M15, tighten InpInitSL_ATR to 1.50, and pull the ratchet stages closer (for example, Stage 1 at 1.20x, Stage 2 at 2.00x locking 1.00x, and Stage 3 at 3.00x trailing 1.20x ATR). Enable InpUseSessionFlatten = true at your preferred end-of-day hour to avoid overnight rollover spreads.
- Swing and Trend-Following Trades (H1 to H4): Keep InpATRTimeframe on PERIOD_H1 or move to PERIOD_H4 with wider breathing room (such as 2.00x Initial SL, Stage 1 at 2.00x, Stage 2 at 3.50x locking 1.50x, and Stage 3 at 5.00x trailing 2.25x ATR) so normal intraday pullbacks do not stop out major runners early.
- Strict Funded Account Rules (5% Daily / 10% Max Loss): Enter your exact starting evaluation balance into InpInitialBalance (for example, 100000.0) so Total DD stays anchored accurately across terminal restarts. Keep InpMaxDailyDDPct at 3.80% to 4.00% and InpMaxTotalDDPct at 8.00% to 8.50% to leave slippage protection ahead of hard account limits, and set InpBaseRiskPct between 0.50% and 1.00%.
- Conservative Two-Step Evaluation Preservation: Lower InpCushionStartDD to 1.00% and InpBaseRiskPct to 0.50% so position sizing automatically cuts back early during slow drawdowns.
- Multi-Pair Portfolio Supervision: Attach the EA to one clean chart (such as EURUSD H1), set InpManageAllSymbols = true and InpMagicNumber = 0, and the single cockpit will monitor account-wide daily and total drawdown while applying symbol-specific ATR ratchets to every open pair independently.
----Managing accounts on MetaTrader 4 instead of MetaTrader 5? The identically engineered MetaTrader 4 edition of Three Stage ATR Ratchet Manager is published on my MQL5 Seller Profile with the exact same thumbnail, 3-stage High-Water-Mark ATR ratchet, drawdown circuit breakers, cushion lot scaling, and instant-render cockpit HUD. Visit my seller profile to access the MT4 version.
