The Optimization Paradox
Optimization is a double-edged sword. Done right, it finds parameters that extract maximum edge from your strategy. Done wrong, it creates a perfectly curve-fitted EA that fails spectacularly in live trading.
The goal isn't finding the "best" parameters. It's finding parameters that are:
Remember: If your EA needs exact parameters to work, it's not a strategy - it's a coincidence.
Genetic Algorithm Settings
MT5 Optimization Modes
Slow complete algorithm:
Fast genetic algorithm:
Recommended GA Settings
``
Population size: 256 (balance speed vs coverage)
Generations: Automatic (let it converge)
Selection: Tournament
Crossover: 0.9 (90% of new population)
Mutation: 0.1 (10% random changes)
``
Optimization Criteria
| Criteria | Best For | |----------|----------| | Balance | Maximizing raw profit | | Profit Factor | Risk-adjusted returns | | Expected Payoff | Consistency per trade | | Drawdown | Minimizing risk | | Sharpe Ratio | Overall risk-adjusted performance | | Custom | Your specific goals |
Our recommendation: Optimize for Profit Factor or Custom criterion that balances profit and drawdown.
Parameter Selection
Which Parameters to Optimize
Good candidates:
Bad candidates (usually):
Setting Parameter Ranges
Too narrow: Might miss better values Too wide: Wastes time testing impossible values
Example - RSI Period:
``
Bad: 2 to 100, step 1 (99 values, many useless)
Good: 10 to 30, step 2 (11 values, all reasonable)
`
Example - Stop Loss (pips):
`
Scalper: 5 to 20, step 5
Day trader: 20 to 60, step 10
Swing trader: 50 to 150, step 25
`
The Stability Rule
Test nearby values for each optimal parameter:
`
Optimal MA period: 21
Test 19, 20, 21, 22, 23
If all are profitable: ROBUST If only 21 works: CURVE-FITTED ``
Walk-Forward Optimization
Walk-forward is the gold standard for finding robust parameters.
How It Works
Example Timeline
``
2019 Jan-Jun: Optimize (In-Sample)
2019 Jul-Sep: Test (Out-of-Sample) ✓
2019 Jan-Sep: Optimize (In-Sample)
2019 Oct-Dec: Test (Out-of-Sample) ✓
2019 Jan - 2020 Jun: Optimize (In-Sample)
2020 Jul-Sep: Test (Out-of-Sample) ✓
...
`
Walk-Forward Efficiency Ratio
`
WF Efficiency = Out-of-Sample Profit / In-Sample Profit
> 0.5: Acceptable (strategy has real edge) > 0.7: Good (robust strategy) > 0.9: Excellent (very stable strategy) < 0.3: Poor (likely curve-fitted) ``
Walk-Forward Matrix (MT5)
MT5's Strategy Tester includes built-in walk-forward testing:
Robustness Testing
Monte Carlo Simulation
Test how your EA performs under randomized conditions:
Use our Monte Carlo Calculator to stress-test your parameters.
Multi-Market Validation
A robust strategy should work on similar markets:
``
Original pair: EURUSD ✓
Test on GBPUSD: ✓ (should also work)
Test on USDJPY: ✓ (should also work)
Test on AUDNZD: ✓ (optional, different dynamics)
``
If it only works on EURUSD, you've likely curve-fitted to that pair's specific history.
Regime Testing
Test across different market regimes:
| Regime | Date Range | Your EA Result | |--------|------------|----------------| | Trending | 2017 | Should be profitable | | Ranging | 2018 | Should survive | | Crisis | 2020 Q1 | Should not blow up | | Recovery | 2020 Q2-Q4 | Should work | | High rates | 2022 | Should adapt |
Implementation Guide
Step-by-Step Optimization Process
Phase 1: Initial Exploration
``
`
Phase 2: Refinement
`
`
Phase 3: Walk-Forward Validation
`
`
Phase 4: Robustness Testing
`
`
Code for Custom Optimization Criterion
`mql5
double OnTester() {
// Get standard metrics
double profit = TesterStatistics(STAT_PROFIT);
double drawdown = TesterStatistics(STAT_EQUITY_DD_RELATIVE);
double trades = TesterStatistics(STAT_TRADES);
double profitFactor = TesterStatistics(STAT_PROFIT_FACTOR);
// Reject if too few trades if(trades < 100) return 0;
// Reject if drawdown too high if(drawdown > 30) return 0;
// Reject if profit factor too low if(profitFactor < 1.2) return 0;
// Custom score: Profit * Profit Factor / Drawdown double score = profit * profitFactor / (drawdown + 1);
return score; } ``
Conclusion
Optimization is an art as much as a science. Here's your checklist:
Before Optimizing
During Optimization
After Optimizing
Red Flags
The final test: If you wouldn't bet your own money on the parameters, don't deploy them.
Need help optimizing your EA? Get a free strategy audit or contact us for professional optimization services.