Prop-Style Drawdown & Risk Protection for MT5 — A Developer & Trader Blueprint

  • 1. Why It Matters: What problem this solves for prop and active MT5 traders.

  • 2. System Architecture: How the pieces fit together (Indicator vs. EA , state storage, timezone math, risk math).

  • 3. Core Feature Spec: The exact modules to build in v1 vs. v2.

  • 4. MQL5 Implementation Traps: Bugs that break real accounts—and how to prevent them.

  • 5. Build & Pitch Roadmap: How to ship a clean MVP or package it for clients/buyers.

1. Why It Matters

Most retail trading tools focus on finding entries. In prop-firm and disciplined intraday trading, accounts rarely blow up because a trader lacked another signal—they blow up because of untracked daily drawdown, timezone confusion around resets, oversized positions on volatile instruments, or emotional revenge trades after a loss.

A well-built MT5 Prop Drawdown & Risk Guard acts as a calm, real-time cockpit and guardrail: it shows exact loss buffers, calculates accurate lot sizes per trade, warns early, and optionally enforces hard stop rules before a bad session turns into a breached account.

2. System Architecture (Your Mental Map)

Think of the system as four decoupled layers so your code stays clean, testable, and easy to maintain:

  1. Time & Session Clock Layer: Converts broker server time (TimeCurrent() ) to the target reset/session timezone (such as New York ET ) and detects when a new trading day starts.

  2. Account & Drawdown Ledger Layer: Captures starting daily balance/equity, tracks peak/high-water equity, computes current daily and overall drawdown in currency ($ ) and % , and persists daily snapshots across chart reloads or MT5 restarts.

  3. Position & Risk Sizing Layer: Reads live symbol contract specs (SYMBOL_TRADE_TICK_VALUE , SYMBOL_TRADE_TICK_SIZE , SYMBOL_POINT , volume min/max/step) to compute lot sizes from a chosen stop distance and dollar/percentage risk.

  4. UI & Guardrail Enforcement Layer: Renders a clean on-chart panel/alerts (Indicator mode) and, if built as an Expert Advisor (EA), enforces optional order blocks, trade limits, or breach actions.

Key Architectural Split: Keep display/monitoring logic modular so you can offer a Monitor Indicator (zero trade interference, pure visibility + alerts) alongside or inside a Guard EA (optional hard lockouts/blocks).

3. Core Feature Spec

Phase 1: MVP (High-Value Core)

  • Daily Drawdown Tracker: Choice of Balance-based, Equity-based, or Max(Balance, Equity) start at daily reset, showing used loss, remaining buffer ($ and % ), and status color (Safe / Warning / Breached ).

  • Max / Overall Drawdown Tracker: Static (from initial account balance) or trailing high-water mark, with clear remaining buffer readout.

  • Configurable Daily Reset: Set reset hour/minute and timezone offset so daily counters roll over at the exact rule time.

  • Risk-Based Lot Calculator: Input target risk ($ or % of balance/equity) + stop-loss in points or price; outputs exact normalized lot size and dollar risk at stop.

  • Early Warning Alerts: Pop-up, sound, push notification, or email alerts at configurable thresholds (e.g., 50% and 80% of daily limit).

Phase 2: Guardrail & Power Features (v1.5 / v2)

  • Max Risk-Per-Trade Cap: Warns or blocks trades whose calculated risk exceeds a set ceiling (e.g., max 1% or $250 per position).

  • Trade Frequency & Session Limits: Optional max trades per day, max open positions, or "no new trades after X time / before rollover" cutoff.

  • Hard Breach Actions (EA Mode Only): Optional toggle to block new orders, cancel pending orders, or close open positions if a hard limit is hit—off or explicitly confirmed by default so users never lock themselves out by accident.

4. MQL5 Implementation Traps to Avoid

  • Losing Daily Baselines on Reload/Restart: Never store daily_start_equity solely in a local variable that resets when the timeframe changes or MT5 restarts. Persist daily baseline values and the active day key using MQL5 Global Variables (GlobalVariableSet / GlobalVariableGet ) or a file state keyed by account number + date.

  • Assuming Server Time = Prop Reset Time: Broker servers run on various GMT offsets and DST schedules. Make timezone offset explicit and well-documented in inputs so a 17:00 or 00:00 reset happens on schedule.

  • Hardcoding Pip Values: Gold (XAUUSD ), US indices, JPY pairs, and crypto differ wildly in tick size and tick value. Always calculate risk per lot from live SymbolInfoDouble() properties and validate against SYMBOL_VOLUME_MIN , SYMBOL_VOLUME_MAX , and SYMBOL_VOLUME_STEP .

  • Trying to Execute Orders Inside an Indicator: In MQL5, indicators are not designed for trade execution reliability the way EAs are. If automated blocking or position closing is in scope, build an EA.

  • No "Safe / Test Mode" Guard: Traders testing an EA on a demo or live account can get frustrated if a test setting immediately closes trades. Include clear status labels and explicit enable flags for any destructive/blocking action.

5. Build & Pitch Roadmap

  1. Build the Math & State Engine First: Get daily reset detection, balance/equity drawdown math, GlobalVariable persistence, and lot-size math working and logged cleanly before polishing UI colors or panels.

  2. Test Across Edge Cases: Run Strategy Tester and live/demo checks across timeframe switches, terminal restarts, multiple symbols (EURUSD , XAUUSD , index CFDs), and simulated limit breaches.

  3. Position It Clearly: Whether pitching a freelance client or publishing a product, lead with rule clarity, accurate drawdown math, and risk control,and explicitly state what is monitoring/alerting vs. automated trade restriction.

Feel free to message me if you'd like to share thoughts, compare setups, or get help troubleshooting your risk or drawdown logic.