Compliance Ready Template
Funded/prop-style accounts are usually governed by rules the EA's own strategy logic has nothing to do with - a daily loss cap, a maximum drawdown from the account's equity peak, a cap on trades per day, a trading-hours window, and often an external emergency stop the trader (or the firm) can trip independently of what the EA is doing. Bolting these checks onto an existing strategy after the fact tends to miss cases, because each one gets added reactively after a specific rule was already broken once. This template inverts that: FirstBlockedGateReason() runs every gate in one place, before any signal is allowed anywhere near OrderSend, and the demo strategy (EvaluateDemoSignal, a plain SMA crossover) is the only piece meant to be swapped out. Every gate decision is written to the audit CSV, including the blocked ones - a reviewer asking "why didn't this account trade at 14:02" needs the BLOCKED row and its reason (which gate, and by how much) as much as the FILLED rows. The gates run cheapest/most-likely first: kill switch, AutoTrading state, trading window, daily loss percentage against the day's starting equity, overall drawdown percentage against the tracked equity peak, trades-opened-today count, and open-position count for this magic - the first one that fails is the one logged and shown on-chart. The kill-switch convention (a KILLSWITCH_ACTIVE GlobalVariable) is deliberately identical to this catalogue's KillSwitchProtocol Library and KillSwitchListener EA, so a switch tripped from either interoperates with this EA out of the box. It is not #included from either, though - every CodeBase submission stands alone (house style section 1) - the same GlobalVariable name is redeclared locally here and would need updating by hand if that convention ever changes upstream. Notes and limitations - The demo strategy is a plain SMA crossover included to give the gate and audit plumbing something real to log against - review and validate before trusting it with a funded account. - Daily-loss and drawdown percentages are computed against equity read at the moment of each check, not against a broker-side "protection" value some funded-account platforms compute server-side; treat this as an independent client-side safety net, not a replacement for the firm's own enforcement. - The trading day rolls over at broker-server midnight, read from TimeCurrent() - if the firm's rules use a different reference timezone for "daily" resets, adjust RollTradingDayIfNeeded() accordingly. - InpObeyKillSwitch only reads the KILLSWITCH_ACTIVE GlobalVariable - it provides no way to trip the switch itself; pair it with a Script, panel, or this catalogue's KillSwitchProtocol Library / KillSwitchListener EA on the tripping side. - The audit CSV accumulates for as long as the file exists; nothing here rotates or archives it automatically - a long-running funded account should periodically move the file out of MQL4\Files\ (or MQL5\Files\ on the native MQL5 build) for record-keeping.
Expert advisor · MT5 · v1.0 · Free
About Compliance Ready Template
Compliance Ready Template is an expert advisor (trading robot) for MetaTrader 5 based on Moving Average. It trades only in the hours you set (time filter) and can size trades from your balance and risk percent. It has 15 settings, such as Fast ma period, Slow ma period and Risk percent. MQL source code included.
Files in the download: ComplianceReadyTemplate.ex5, ComplianceReadyTemplate.mq5, ComplianceReadyTemplate.txt.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
Settings
| Setting | Default | What it does |
|---|---|---|
| Fast ma period | 10 | Fast MA period for the demo signal |
| Slow ma period | 30 | Slow MA period for the demo signal |
| Risk percent | 0.5 | Risk per trade, percent of equity |
| Stop loss pips | 25 | Stop-loss distance in pips |
| Take profit pips | 50 | Take-profit distance in pips |
| Magic number | 49800 | Magic number for this instance's positions |
| Daily loss limit pct | 4.0 | Block new trades once today's loss exceeds this % of the day's starting equity |
| Max drawdown pct | 8.0 | Block new trades once overall drawdown from peak equity exceeds this % |
| Max trades per day | 6 | Block new trades once this many have opened since the trading-day rollover |
| Max open positions | 1 | Block new trades if this many are already open for this magic |
| Max lot size | 1.0 | Hard cap on any single order's lot size, regardless of risk sizing |
| Trading start hour | 0 | Trading window start, broker time, 0-23 (set equal to End to disable the window) |
| Trading end hour | 24 | Trading window end, broker time, 1-24 (24 = midnight, i.e. open all day) |
| Audit log name | ComplianceReadyTemplate_audit.csv | Append-only audit trail, in MQL5\Files\ |
| Obey kill switch | true | If true, refuses to trade while KILLSWITCH_ACTIVE is set |
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 → Experts.
- 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 expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
- Test it first on a demo account or in the Strategy Tester.
Tags: Buy/Sell Arrows · Risk & Lot Size · Time Filter · Moving Average · MT5 Expert Advisor · MQL5 Source Code