Backtest & Optimize EAs Like a Pro
Professional EA validation demands rigorous backtesting beyond basic MT5 runs.
ViraFX
1 min read
Professional EA validation demands rigorous backtesting beyond basic MT5 runs—aim for real-market replication via tick data, variable spreads, and forward-testing. Setup Phase: Download 99% quality tick data (Dukascopy/Tick Data Suite). MT5 Strategy Tester > Expert tab > Visual mode off > Spread=1.2 pips (model current). Period: 5+ years (2020-2025), deposit $10K, leverage 1:100.
Core Metrics to Target:
Profit Factor (PF) >1.5 (gross profit/loss)
Sharpe Ratio >1.2 (risk-adjusted)
Max Drawdown (MDD) <15%
Recovery Factor >3 (profit/MDD)
Expectancy >0.5 pips/trade
Walk-Forward Analysis (Gold Standard): Split data 70/30 (in-sample/out-sample). Optimize on 2020-2023 (genetic algorithm, 5000 generations), test 2024-2025 forward. Roll monthly: Retrain Q1 on new data. Example: EMA crossover EA optimizes Fast=12/Slow=26 in-sample, validates 14/21 out-sample (PF drops <10% = robust).
Optimization Best Practices:
Parameter Ranges: EMAs 8-50, RSI 10-21, ATR multipliers 1-3. Avoid extremes.
Genetic vs. Exhaustive: Genetic for 10+ params (faster, 95% accuracy).
Multi-Currency: Optimize EUR/USD, validate GBP/USD (no overfitting).
Out-of-Sample Test: >80% in-sample performance retained.
Monte Carlo: Reshuffle trades 1000x—expectancy holds?
Common Pitfalls & Fixes:
Curve-Fitting: Solution—Walk-forward + smaller datasets.
Look-Ahead Bias: Use shift=1 for indicators.
Spread Slippage: Model commissions ($7/lot round-turn).
News Gaps: Skip high-impact events or add FFCal filter.
Sample MQL5 Walk-Forward EA Code:
#property strict
extern double Lots = 0.01;
extern int FastEMA = 14;
extern int SlowEMA = 21;
extern double ATRMult = 2.0;
extern int Magic = 123456;
// OnTick logic
double fast = iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,1);
double slow = iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,1);
double atr = iATR(NULL,0,14,1) * ATRMult;
if(fast > slow && OrdersTotal()==0) {
OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-atr,Ask+atr*1.5,"WF Buy",Magic);
}
Source / reference to read on and on.
Here we share the references and sources that inspire and support our blog content, ensuring you get well-researched and reliable information.
© 2025 ViraFX Solutions Pvt. Ltd. All rights reserved.
ViraFX Solutions
Legal
Contact
Do Check
