Join our fan page
- Views:
- 83
- Rating:
- Published:
-
Need a robot or indicator based on this code? Order it on Freelance Go to Freelance
A prop-firm account runs under a second rulebook MetaTrader 5 knows nothing about: a maximum loss measured from a fixed starting balance, a daily limit that resets at an hour the broker's clock does not agree with, a payout consistency ceiling, a minimum number of trading days, a news blackout, a Friday cutoff. Break the first rulebook and you lose a trade. Break the second and you lose the account.
This library is the source form of the guard behind it. It compiles into any EA, checks eight rules on one frozen account snapshot per pass, and reports at most one directive out of it — never eight separate reactions to one bad moment. It takes no position of its own.

What is in the archive
24 header files (.mqh), one facade class (CPropRulebook) and a demo Expert Advisor (PropFirmDefense.mq5) that wires the facade to an on-chart panel. The demo is also published, compiled, as a free product on the Market: PropFirm Defense. This CodeBase entry is the same guard in source form, for readers who want the classes rather than the binary.
What it checks
- Eight rules on every pass — static drawdown, trailing drawdown, daily loss, profit target, payout consistency, minimum trading days, news blackout, weekend flat.
- A trailing floor that behaves like the real thing — it ratchets up with the peak and then freezes permanently once the balance reaches start plus trail, the way trailing-drawdown accounts actually work.
- The daily reset in the firm's time zone, not at the broker's midnight, so a loss booked either side of the boundary lands on the correct day.
- Payout rules never close a position. A consistency or minimum-days problem withholds a withdrawal, it does not put the account at risk, so the guard reports it instead of acting on it.

How it behaves
- One observation per pass, shared by every rule, and at most one directive out of it. Eight rules breaching at once produce one action, not eight.
- Works alongside anything — any EA, manual trading or copied signal on the account. It takes no position of its own.
- State survives a restart. The anchor, the consumed budget and the latches are persisted, so a VPS reboot does not refill the drawdown allowance.
- Every threshold is yours to set, from the Inputs dialog, with presets for common firm styles as a starting point.

Architecture, for readers who want to reuse the pieces
CPropRulebook is the only class a caller needs. It composes:
- CPropSnapshotBuilder — freezes one account snapshot per pass (equity, balance, positions, floating P/L) so every rule judges the same numbers.
- CRuleRegistry + CRuleCoordinator — hold the eight IPropRule implementations and resolve many verdicts into at most one directive.
- CProtectiveActionExecutor — the only class allowed to touch a position, and only to flatten on breach.
- CGuardStateStore — persists the trailing floor, consumed budgets and latches across a terminal restart.
- CTerminalAlgoSwitch — an optional actuator for the terminal's global Algo Trading button. It degrades instead of refusing to start when the WinAPI call it needs is unavailable (Market build, Linux/Wine, or AllowDllImport=0).
Not a strategy
This does not decide when to enter and makes no claim about profitability. It answers two questions for whatever does trade: may I open this now, and is anything about this account currently in breach.
Limitations, stated up front
- Preset numbers are a starting point, not a contract. Prop-firm rulebooks change and differ per programme and per tier. Check every threshold against your own agreement.
- The news rule needs the terminal's economic calendar. It abstains when the calendar is unavailable, which is the case in the Strategy Tester.
- CTerminalAlgoSwitch imports user32.dll when compiled without the market-build switch (PROP_MARKET_BUILD, on by default in the attached demo). If you compile your own entry point and need the DLL-free path (Market rules, AllowDllImport=0, or a platform with no WinAPI), define that macro before the include.
MSNR Key Levels MTF
MSNR KeyLevels MultiTF draws Malaysian SNR key levels from M5, M10, M15, H1, H4 and D1 at the same time, on any chart you have open. A built-in control panel lets you switch each timeframe on and off with a single click, so you go from a clean chart to full higher timeframe context in a second, and back again just as fast.
RJO Daily Pivot Levels Classic and Fibonacci for MT5
Daily Pivot Points indicator for MetaTrader 5 with Classic and Fibonacci methods. Displays PP, R1-R3 and S1-S3 using the previous completed daily candle.
Range compression percentile
Ranks the current period's range-so-far against the full historical distribution of past ranges — a true percentile, not just a comparison to the average like ADR% — and flags statistical compression or expansion on a compact live panel with a percentile gauge.
MACD Signals
Indicator edition for new platform.