How to build a prop firm-compliant EA for MT5 — complete guide
How to build a prop firm-compliant EA for MT5 — complete guide
Algorithmic Trading • technical guide
Table of Contents
What prop firm rules actually mean in MQL5 code
Proprietary trading firms enforce strict quantitative rules designed to test risk management. In MQL5, compliance is not merely about setting stop losses—it requires active equity tracking, high-water mark calculations, and automated execution halts. - **Daily Drawdown Limit**: Calculated from the starting balance/equity of the trading day (typically 00:00 server time). - **Maximum Total Loss**: Hard equity limit based on initial account size. - **Trailing Equity Stop**: High-water mark trailing loss threshold that moves up as profit grows.Need a custom quantitative solution?
We scope, backtest, and build institutional-grade software systems designed specifically around your proprietary strategy rules under a strict NDA.
BOOK A FREE STRATEGY CALL→Daily drawdown, max loss and trailing equity stops — how to implement each
1. Daily Drawdown Engine
The daily drawdown monitor captures equity at midnight server time and halts trading if loss threshold is breached: ``mql5
//+------------------------------------------------------------------+
//| Daily Drawdown Verification |
//+------------------------------------------------------------------+
datetime lastReset;
double startOfDayEquity;
void CheckDailyDrawdown(double maxDailyLossPct) {
MqlDateTime dt;
TimeToStruct(TimeCurrent(), dt);
if(dt.hour == 0 && dt.min == 0 && dt.day != lastReset) {
startOfDayEquity = AccountInfoDouble(ACCOUNT_EQUITY);
lastReset = dt.day;
}
double currentEquity = AccountInfoDouble(ACCOUNT_EQUITY);
double maxLossAllowed = startOfDayEquity * (maxDailyLossPct / 100.0);
if(startOfDayEquity - currentEquity >= maxLossAllowed) {
CloseAllPositions();
GlobalVariableSet("EA_HALT_TODAY", 1);
}
}
`
2. Trailing Equity Stops
Relative trailing drawdown tracks maximum account equity and locks in hard stops:
`mql5
double highWaterMark = 0;
void CheckTrailingEquityStop(double maxTrailingDrawdownPct) {
double currentEquity = AccountInfoDouble(ACCOUNT_EQUITY);
if(currentEquity > highWaterMark) {
highWaterMark = currentEquity;
}
double maxAllowedLoss = highWaterMark * (maxTrailingDrawdownPct / 100.0);
if((highWaterMark - currentEquity) >= maxAllowedLoss) {
CloseAllPositions();
ExpertRemove(); // Emergency removal to halt trading
}
}
``
News filter logic
High-impact economic news releases create slippage and spread spikes. Implementing a news filter involves querying an economic calendar API or reading an embedded news CSV file to halt entry orders 15 minutes before and after high-impact events.Testing your EA against prop firm conditions before submission
Standard MetaTrader backtesting does not capture variable spreads or tick-level slippage. Before submitting to a prop firm: - Run backtests with **every tick based on real ticks**. - Simulate **stress spreads** (e.g., 50-100 points during rollover). - Perform **walk-forward optimization** across multiple market regimes.Common mistakes that get EAs flagged
1. **Grid & Martingale Logic**: Most prop firms use automated detectors that flag doubling lot sizes after losses. 2. **Trade Copying Collusion**: Using identical magic numbers, lot sizing, and entry timestamps across multiple client accounts. 3. **Rollover Execution**: Opening orders during 23:59-00:05 server rollover when liquidity thins out and spreads widen by 10x.About the PSI Square Team
We are a team of quantitative developers, AI system architects, and full-stack software engineers specializing in execution latency optimization, autonomous systems orchestration, and custom broker integrations.
WHY CHOOSE US →Related Articles
SEE ALL GUIDES →MT4 vs MT5 for algorithmic trading — what actually matters in 2025
Comprehensive technical comparison of MT4 vs MT5 focusing on execution models, MQL4 vs MQL5 differences, multi-currency backtesting, and engine speed.
How trade copiers work — architecture, latency and what to watch out for
Deep dive into trade copier architecture, low-latency socket bridges, slippage mitigation, lot scaling logic, and order rejection handling in MT5 system.
TradingView Pine Script to MT5 — how to automate your strategy
Learn how to automate TradingView Pine Script strategies on MetaTrader 5 using webhook bridges, JSON alert payloads, and resilient MQL5 execution EAs.
Ready to engineer your custom system?
Discuss your logic, requirements, and platform goals with our engineers and developers under a complete mutual NDA.
SCHEDULE AN AUDIT CALL