Account Protection — System Level

8. Account Protection — System Level

Daily Loss Hard Limit

If daily P/L drops below -(Inp_Daily_Loss_HardLimit)% of balance:
  → g_DailyLossReached = true
  → ALL new orders blocked for the rest of the day
  → Existing positions continue to be managed

Default: 4% of balance.

Drawdown Freeze

If current drawdown > Inp_Drawdown_FreezeLimit%:
  → g_DrawdownFreeze = true
  → New orders frozen

Default: 0.5% (very conservative, ideal for prop firm challenges).

Daily Target Profit

If daily P/L > +Inp_Daily_Target_Profit%:
  → g_DailyTargetReached = true
  → Trading stopped — profit is secured

Default: 15% — after reaching the target, the system shuts itself down for the day.

Equity Trailing Lock (Master)

An equity protection mechanism operating at the account level:

If equity rises by >= Inp_Equity_TSL_Trigger%:
  → Sets an "equity high watermark"
  → If equity drops below (high - Inp_Equity_TSL_Buffer%):
     → Closes ALL positions immediately

Default: Trigger 5%, Buffer 0.2%. Protects against losing a large intraday gain.

Architecture & Module Connections

1. Architecture & Module Connections

The system is composed of five header files included into the compiled main file _AHS_Main.ex5:

_AHS_Main.ex5
  ├── AHS_Inputs.mqh      → All input parameters, enumerations, global state variables
  ├── AHS_Filters.mqh     → Market filters (The Shield): Macro Matrix, Impulse, Channel, ADX/MA, SmartDI, MTF, 3Candles
  ├── AHS_Strategy.mqh    → Multi-Core Engine: position sizing, order execution
  ├── AHS_Management.mqh  → Position management: TSL BB, Hard BE, Neg BE, Dynamic TP, EOD Terminator
  └── AHS_Panel.mqh       → Graphical information panel: status, MTF dashboard, positions list

OnTick() Flow — Step by Step

Every incoming tick passes through a strictly defined sequence in the main loop:

OnTick()
  1.  License check (CLicenseManager.IsExpired)
  2.  Session schedule check (IsScheduleAllowed)
  3.  EOD Terminator (CheckForEODClose) → emergency close all positions
  4.  Daily P/L update and daily reset
  5.  Account Protection checks:
        → DailyLossReached?    → block new orders
        → DrawdownFreeze?      → block new orders
        → DailyTargetReached?  → block new orders
  6.  Equity Trailing Lock (master equity trailing SL)
  7.  Institutional Impulse Detection (CheckInstitutionalImpulse)
  8.  Dynamic Channel Update (UpdateDynamicChannel) every X hours
  9.  News Filter → freeze before/after news events
 10.  ManageAllPositions() → manage all open positions
 11.  Cooldown check + position count limit check
 12.  EvaluateStrategies() → Multi-Core Engine searches for a signal
 13.  Information panel update

All stages are independent — position management (step 10) runs regardless of whether new signals are being sought (step 12). Even when new orders are blocked, open positions are always managed.