Prop Firm Rule Guard
Funded-account challenges fail traders for reasons that have nothing to do with strategy edge: a daily loss limit breached by one bad session, a trailing drawdown from the account's own equity peak, or a consistency rule that voids a pass because one lucky day carried the whole result. None of these are things the platform tracks for you, and all of them need state that survives across ticks - a running equity peak, a day-start balance, the best single day's profit on record. This library follows the pattern used throughout this catalogue for any rule that needs memory: the caller owns a PfgState struct and passes it by reference into PfgUpdate once per tick (or once per bar - it is cheap enough for either). Nothing is hidden in a global, so more than one guard can run at once without fighting over shared state, and every read function is a pure calculation over that struct and the account's current numbers. Four rules are covered. PfgIsDailyLossBreached fires once equity falls further than a percent limit below the current day's starting balance. PfgIsTrailing DrawdownBreached fires once equity falls a percent limit below its own running peak - deliberately measured from EQUITY, not balance, which is the stricter and more common convention: an open floating loss counts against the limit immediately, not only once a losing trade closes. PfgIsProfitTargetReached checks progress toward the pass condition. PfgIsConsistencyBreached checks whether the single best day's profit exceeds an allowed share of total profit, the rule that stops one outsized day from carrying an otherwise unconvincing result. PfgIsChallengeFailed bundles the two hard-fail rules - daily loss and trailing drawdown - into one check, deliberately leaving the profit target and consistency rule out of it, because those two are goals to work toward, not failures to trip an EA's kill switch over mid-challenge. The header is self-contained. No dependencies, no DLLs - one small struct and plain functions that operate on it. It also does not read equity, balance or the clock itself: the caller supplies those as plain parameters, which is what keeps the same struct and functions identical on both platforms. Notes and limitations - Firms differ on whether trailing drawdown trails equity or balance, and on whether it trails the all-time peak or only resets at each new profit target milestone. This header trails EQUITY against the all-time peak, the strictest common convention - confirm your specific firm's rule before relying on this in a live challenge and adjust the inputs you pass in if it differs. - A day's profit is only folded into bestDayProfit once the calendar rolls into the next day. The still-open current day is not yet reflected in PfgConsistencyRatio - call PfgUpdate with a rolled-forward timestamp (or wait for the actual next day) before trusting the consistency reading at the end of a session. - "New day" is judged by dividing the UNIX timestamp by 86400, which follows UTC day boundaries as the platform reports them, not the server's or firm's own trading-day cutoff. If your firm defines its day boundary at a specific broker time (a common convention), adjust nowTime before passing it in. - This header does not place, close or modify any order on either platform. It only answers questions about account state - wiring a breach to actually flatten positions is left to the caller, as shown in the usage examples. - No thread or state concerns beyond the struct itself: every function is a pure read except PfgInit and PfgUpdate, which are the only two that write to it.
Script · MT5 · v1.0 · Free
About Prop Firm Rule Guard
Prop Firm Rule Guard is a script for MetaTrader 5. It has 5 settings, such as Starting balance, Max daily loss percent and Max trailing dd percent. MQL source code included.
Files in the download: PropFirmRuleGuard.mq5.mqh, PropFirmRuleGuard.txt, PropFirmRuleGuardDemo.ex5, PropFirmRuleGuardDemo.mq5.
Settings
| Setting | Default | What it does |
|---|---|---|
| Starting balance | 100000.0 | Challenge starting balance |
| Max daily loss percent | 5.0 | Daily loss limit, percent |
| Max trailing dd percent | 10.0 | Trailing drawdown limit, percent |
| Profit target percent | 8.0 | Profit target, percent |
| Max consistency share | 0.40 | Max share of profit from one day |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Dashboards & Scanners · Trading Sessions · Trailing Stop & Break-even · MT5 Script · MQL5 Source Code