Backtesting & Strategy Optimization

Use the MT5 Strategy Tester to backtest EAs, interpret results, and optimize parameters without overfitting.

What is Backtesting?

Backtesting is the process of running your Expert Advisor on historical market data to see how it would have performed in the past. It is the most important step before deploying any automated strategy — it reveals whether your idea has statistical merit or is just wishful thinking.

The MT5 Strategy Tester

Open the Strategy Tester with Ctrl + R. Key settings:

  • Expert — Select your EA from the dropdown
  • Symbol — The instrument to test on
  • Period — Chart timeframe
  • Date range — Start and end dates for the test (use at least 1-2 years)
  • Modeling — "Every tick based on real ticks" is most accurate but slowest. "1 minute OHLC" is a good balance. "Open prices only" is fastest but only accurate for strategies that trade on bar open.
  • Deposit — Starting account balance for the simulation
  • Leverage — Account leverage setting

Understanding Backtest Results

After a backtest completes, examine these tabs:

Graph tab: Shows the equity curve (blue) and balance curve (green) over time. A smooth, upward-sloping equity curve is ideal. Large drawdowns and flat periods are warning signs.

Report tab — Key metrics:

  • Net Profit — Total profit minus total loss. Must be positive.
  • Profit Factor — Gross profit / Gross loss. Above 1.5 is good, above 2.0 is excellent.
  • Max Drawdown — The largest peak-to-trough decline in equity. Keep this below 20-30% of the starting balance.
  • Win Rate — Percentage of profitable trades. High win rate with low profit factor means small wins and large losses (bad). Low win rate with high profit factor means large wins and small losses (can be good).
  • Sharpe Ratio — Risk-adjusted return. Above 1.0 is acceptable, above 2.0 is very good.
  • Recovery Factor — Net profit / Max drawdown. Above 3.0 is robust.
  • Total Trades — Need at least 100+ trades for statistical significance.
⚠️
Good backtest does not equal good strategy

Backtests are simulations with perfect hindsight. Real trading involves slippage, variable spreads, requotes, and changing market conditions that backtests cannot fully capture.

Parameter Optimization

The Strategy Tester can automatically test thousands of parameter combinations to find optimal settings:

1
Switch to Optimization mode

In the Strategy Tester, change the mode from "Single" to "Optimization."

2
Set parameter ranges

In the Inputs tab, check the parameters to optimize and set Start, Step, and Stop values. For example: Fast MA from 5 to 30 step 5, Slow MA from 30 to 100 step 10.

3
Choose optimization criterion

Optimize by: Maximum profit, Maximum Sharpe Ratio, Minimum drawdown, or custom criterion. Sharpe Ratio is generally the best choice as it balances profit and risk.

The Overfitting Trap

Overfitting (curve fitting) is the biggest danger in optimization. It occurs when you optimize parameters so precisely that the EA perfectly fits historical data but fails on new data.

Signs of overfitting:

  • Only a narrow range of parameters is profitable (all nearby values lose money)
  • Performance degrades dramatically on a different time period or symbol
  • The strategy requires very specific values (e.g., MA 37 works but MA 35 and MA 39 do not)
  • Too many optimizable parameters relative to the number of trades

Walk-Forward Testing

The gold standard for validating a strategy:

  • In-sample period — Optimize parameters on this data (e.g., 2023-2024)
  • Out-of-sample period — Test the optimized parameters on data the optimizer never saw (e.g., 2025)
  • If performance degrades significantly on out-of-sample data, the strategy is likely overfitted
  • Repeat with rolling windows (optimize Jan-Jun, test Jul-Sep; optimize Apr-Sep, test Oct-Dec)

Practical Backtesting Checklist

  • Use "Every tick based on real ticks" for final validation
  • Set realistic spread and commission in the tester settings
  • Test on at least 2 years of data with 200+ trades
  • Test on multiple symbols — a robust strategy works across related instruments
  • Reserve 30% of your data for out-of-sample testing
  • Look for parameter stability: nearby parameter values should also be profitable
  • After optimization, run the EA on a demo account for 1-3 months before live trading