Skip to content

How to Backtest an EA in MetaTrader: MT4/MT5 Strategy Tester Guide

Learn how to backtest an EA in the MetaTrader 4 and 5 Strategy Tester, optimize parameters, and interpret results to assess a trading strategy.

Admin
Article cover: How to Backtest an EA in MetaTrader: MT4/MT5 Strategy Tester Guide

Testing an EA in the MetaTrader Strategy Tester is essential before running a trading robot on a live account. This guide explains how to backtest an EA in MT4 and MT5, optimize its parameters, and interpret test results to assess the strategy’s profitability.

# How to Test an EA in the MetaTrader Strategy Tester: Complete Guide

Backtesting an expert advisor (EA) on historical data is essential before using it on a live account. MetaTrader’s Strategy Tester can assess several years of strategy performance in just a few minutes. This article explains how to test EAs correctly and interpret the results.

Why backtest an EA?

Benefits of testing:

✅ Check profitability: see whether the strategy works in principle
✅ Assess risk: examine maximum drawdown and volatility
✅ Optimize parameters: find the best settings
✅ Save time: simulate years of trading in minutes
✅ Save money: avoid risking real capital

What the tester CANNOT show:

❌ Slippage in live trading
❌ Changes in the broker’s spreads
❌ Technical failures (internet or VPS outages)
❌ Exceptional events (sudden news, gaps)

Editor's note: The blanket limitations listed above need platform-specific context: MetaTrader 5 real-tick tests can use spreads that vary within a minute. The source's general warning is retained, but test settings should be checked against the official MT5 tick-generation documentation.

Conclusion: Backtesting is necessary but insufficient. After using the tester, always run the EA on a demo account for at least 2-4 weeks.


Preparing to test

Step 1: Download historical data

Reliable testing requires at least 1-2 years of data.

In MetaTrader 4:

  1. Select Tools → History Center (F2)
  2. Choose a currency pair (such as EURUSD)
  3. Choose a timeframe (M1 for scalping, H1/H4 for medium-term trading)
  4. Click Download to load data from the broker’s server
  5. Repeat for all required pairs and timeframes

In MetaTrader 5:

  1. Select View → Symbols (Ctrl + U)
  2. Select a symbol → the Ticks tab
  3. Click Request to download tick data for recent years

Important: Data quality depends on the broker. For accurate testing, use brokers with a long history (5+ years).

Step 2: Check data quality

Poor data = misleading test results!

Signs of poor data:

  • Large gaps (missing history)
  • Spreads of 0-1 points (unrealistic)
  • Spreads of 50+ points (anomalous)
  • Missing weekends

Quality check:

Open a chart → Right-click → Properties → Common tab
Check:
- Start of history (earlier is better)
- Number of bars (more = better)

Step 3: Choose a modeling mode

MT4 has 3 testing modes:

Mode Accuracy Speed When to use
Every tick 99% Slow Scalping, news strategies
Control points 90% Moderate Medium-term trading
Open prices only 25% Fast Preliminary testing

Editor's note: The accuracy percentages in the source table are not guarantees inherent to each modeling mode. Data quality and tester configuration matter, and MT4 and MT5 capabilities differ. See the official MT4 modeling-method reference.

Recommendation: Always use “Every tick” or “Every tick based on real ticks” (MT5) for the final test.


Running a test: step-by-step instructions

For MetaTrader 4:

Step 1: Open the Strategy Tester

View → Strategy Tester (Ctrl + R)

Step 2: Configure the test

Expert Advisor: Choose your EA from the list
Symbol:         EURUSD (or another pair)
Model:          Every tick (the most accurate mode)
Period:         H1 (or the timeframe used by the EA)
Use date:       ✅ Enabled
From:           01.01.2022 (at least 1 year ago)
To:             31.12.2023 (up to the current date)
Optimization:   ❌ Disabled (for the first test)
Visual mode:    ❌ Disabled (speeds up the test)

Step 3: Configure the EA inputs

Click Expert properties:

Testing tab:
- Initial deposit: 10000 (recommended)
- Optimization: Balance + maximum
- Currency: USD (or your account currency)

Inputs tab:
- Configure EA parameters (Lot, SL, TP, etc.)

Step 4: Start the test

Click Start to begin testing.

Progress appears as a percentage. Typical testing times:

  • “Every tick” on M1 over 2 years = 5-30 minutes
  • “Control points” = 1-5 minutes

For MetaTrader 5:

The process is similar to MT4, with improvements:

MT5 differences:

  • Mode: “Every tick based on real ticks” (the most accurate)
  • Deposit: Any currency can be specified (USD, EUR, RUB)
  • Forward testing: Automatic re-optimization is available

Analyzing test results

When the test finishes, the Results tab opens with detailed statistics.

Key profitability metrics:

1. Total Net Profit

The overall profit across the testing period.

Example: Total Net Profit = $2,340

✅ Good result: Positive profit
❌ Poor result: Negative or near-zero profit

Important: Look beyond the absolute amount to Return % (ROI):

ROI = (Profit / Initial deposit) × 100%

Example: $2,340 / $10,000 × 100% = 23.4% over 2 years
That is ~11.7% per year—a good result!

2. Profit Factor

The ratio of gross profit from winning trades to gross loss from losing trades.

Profit Factor = Gross profit / Gross loss

Interpretation:

Profit Factor Assessment
< 1.0 ❌ Losing strategy
1.0 - 1.3 ⚠️ Weak strategy (high risk)
1.3 - 1.8 ✅ Acceptable strategy
1.8 - 3.0 ✅ Good strategy
> 3.0 🚨 Too good (possibly overfit)

Example:

Gross Profit: $12,500
Gross Loss: $8,200
Profit Factor = 12,500 / 8,200 = 1.52 ✅ Acceptable

3. Maximum Drawdown

The largest decline in balance from a peak to a trough.

Absolute Drawdown: $1,200 (12% of a $10,000 deposit)

Editor's note: The source places an Absolute Drawdown example under Maximum Drawdown. These are different measures; retain the original figures, but check the report's exact metric and whether it is based on balance or equity before interpreting risk.

Acceptable values:

Drawdown Assessment
< 10% ✅ Conservative strategy
10% - 20% ✅ Moderate strategy
20% - 30% ⚠️ Aggressive strategy
30% - 50% ❌ Dangerous strategy
> 50% 🚨 Unacceptable!

Important: If drawdown is > 30%, the strategy is too risky. Reduce lot size or change the parameters.

4. Win Rate

Total Trades: 150
Profit Trades: 90 (60%)
Loss Trades: 60 (40%)

Interpretation:

Win Rate Assessment Note
> 70% ✅ Excellent But check the SL/TP ratio
50% - 70% ✅ Good Standard range
40% - 50% ⚠️ Satisfactory Requires a high TP/SL ratio
< 40% ❌ Poor Too many losses

A paradoxical example:

Strategy A: Win Rate 80%, but TP = 10 points, SL = 50 points → Unprofitable!
Strategy B: Win Rate 40%, but TP = 100 points, SL = 30 points → Profitable!

That is why Average Win / Average Loss matters:

Average Win: $95
Average Loss: $55
Ratio = 95 / 55 = 1.73 ✅ Good!

5. Recovery Factor

Shows how quickly the strategy recovers from drawdowns.

Recovery Factor = Net Profit / Max Drawdown

Example: $2,340 / $1,200 = 1.95

Interpretation:

Recovery Factor Assessment
< 1.0 ❌ Does not compensate for the risk
1.0 - 2.0 ⚠️ Acceptable
2.0 - 5.0 ✅ Good
> 5.0 ✅ Excellent

Balance and equity curves

Always analyze the charts as well as the numbers:

Balance curve:

✅ A good curve:

  • Smooth growth
  • Infrequent drawdowns
  • A consistent upward slope

❌ A poor curve:

  • Sharp jumps up/down
  • Long periods without profit
  • One enormous gain (martingale)

Equity curve:

Equity is the balance adjusted for open positions.

✅ A healthy strategy:

  • Equity tracks Balance
  • Small deviations (floating profit/loss)

❌ A dangerous strategy:

  • Equity sits far below Balance
  • Losing positions are held for long periods
  • Sharp equity declines

Optimizing EA parameters

After the first test, you can optimize parameters to find the best settings.

How to start optimization:

Step 1: Enable optimization

Strategy Tester → Optimization: ✅ Enabled

Step 2: Choose parameters to optimize

Click Expert properties → Inputs:

Parameter: Lot
✅ Enabled for optimization
Start: 0.01
Step: 0.01
Stop: 0.10

Parameter: StopLoss
✅ Enabled
Start: 20
Step: 5
Stop: 50

Parameter: TakeProfit
✅ Enabled
Start: 30
Step: 10
Stop: 100

Important: Do not optimize too many parameters at once (a maximum of 3-4), or the test will take days!

Step 3: Choose an optimization criterion

Optimization: Balance + maximum

Available criteria:

  • Balance: maximize profit (may ignore risk)
  • Profit Factor: balance profit and risk
  • Recovery Factor: fast recovery from drawdowns
  • Custom: your own formula

Recommendation: Use Profit Factor for safe optimization.

Editor's note: Profit factor alone does not make optimization safe or measure drawdown. Compare risk, costs, sample size and out-of-sample behavior rather than treating this criterion as a safety guarantee.

Step 4: Run optimization

Click Start. The process can take a few minutes to several hours.

Analyzing optimization results:

When optimization finishes, the Optimization Results tab opens with a table of all parameter combinations.

Sort by:

  • Result: final profit
  • Profit Factor: the profit/loss ratio
  • Drawdown: minimize risk

Select the top 5 combinations and test them separately on other periods (Forward Testing).


The danger of overfitting

What is overfitting?

It happens when an EA fits historical data perfectly but loses money in live trading.

Signs of overfitting:

❌ Profit Factor > 5.0 (too good to be true)
❌ Win Rate > 90% (unrealistic)
❌ An excessively narrow range of profitable parameters
❌ Results collapsing after a minor parameter change

How to avoid overfitting:

✅ Use Forward Testing

Split the testing period:

  • In-Sample (training): 70% of the data (for example, 2020-2022)
  • Out-of-Sample (validation): 30% of the data (2023)

Optimize on In-Sample, then validate on Out-of-Sample. If results differ substantially, that indicates overfitting!

✅ Test on several currency pairs

If an EA is profitable only on EURUSD but loses money on GBPUSD and USDJPY, it is overfit to one pair.

✅ Check parameter stability

Change the optimal Lot from 0.05 to 0.06: the result should be similar. If profit falls by a factor of 2, that indicates overfitting.


Practical testing checklist

Use this checklist before running an EA on a live account:

Preparation:

  • Downloaded at least 1-2 years of historical data
  • Checked data quality (no gaps, realistic spreads)
  • Selected “Every tick” or “Real ticks” (MT5)
  • Set a realistic initial deposit ($1,000 - $10,000)

Testing:

  • Tested on the In-Sample period (70% of data)
  • Profit Factor > 1.3
  • Maximum Drawdown < 30%
  • Win Rate > 40% (or a high Average Win / Average Loss)
  • Recovery Factor > 1.5
  • The balance curve rises smoothly

Optimization:

  • Optimized no more than 3-4 parameters
  • Validated on the Out-of-Sample period (30% of data)
  • Out-of-Sample results are close to In-Sample (deviation < 30%)
  • Tested on several currency pairs
  • Parameters are stable (small changes do not collapse profits)

Final checks:

  • Ran on a demo account for at least 2-4 weeks
  • Demo results are close to tester results
  • Checked behavior around news and weekends
  • Have an action plan for drawdown > 20%

Example of interpreting results

Let us compare two EAs and choose the better one:

Editor's note: The source's example metric sets below are internally inconsistent: the trade counts, win rates and average gains/losses do not reconcile with the stated net profits and profit factors. All original figures are retained as illustrative source assertions, not independently verified performance records.

EA #1: “SafeScalper”

Total Net Profit:     $3,200
Profit Factor:        1.68
Max Drawdown:         $980 (9.8%)
Total Trades:         420
Win Rate:             62%
Average Win:          $45
Average Loss:         $32
Recovery Factor:      3.27

Assessment: ✅ Good strategy

  • Consistent profit
  • Low drawdown (<10%)
  • Reasonable Profit Factor
  • High Recovery Factor

EA #2: “AggroMartingale”

Total Net Profit:     $8,500
Profit Factor:        1.42
Max Drawdown:         $4,800 (48%)
Total Trades:         85
Win Rate:             95%
Average Win:          $120
Average Loss:         $4,200
Recovery Factor:      1.77

Assessment: ❌ Dangerous strategy

  • High profit, BUT...
  • Drawdown of 48% (disastrous!)
  • A suspicious 95% Win Rate
  • Huge Average Loss (martingale)
  • One large loss could wipe out the account

Conclusion: Choose EA #1 (SafeScalper). It is less profitable but much safer!


Common testing mistakes

❌ Mistake 1: Testing a short period

Problem: Testing for 1-3 months produces perfect but unrepresentative results.

Solution: Test at least 1-2 years to cover different market conditions (trends, ranges, volatility).

❌ Mistake 2: Ignoring spread

Problem: Testing with a fixed 2-point spread when the broker provides 5-10 points.

Solution: Set a realistic spread for your broker or test with variable spread (MT5).

❌ Mistake 3: Trusting numbers alone

Problem: Looking only at Profit Factor and ignoring the balance curve.

Solution: ALWAYS analyze the chart! Smooth growth = a consistent strategy.

❌ Mistake 4: Over-optimization without Forward Testing

Problem: Optimizing on all the data, then finding the EA does not work in live trading.

Solution: Use an In-Sample / Out-of-Sample split.

❌ Mistake 5: Skipping the demo account

Problem: “The tester showed a profit, so straight to live!”

Solution: ALWAYS test on demo for 2-4 weeks. Actual conditions can differ greatly from the tester.


Tools for advanced analysis

Additional metrics:

Sharpe Ratio

  • Measures risk-adjusted return
  • Higher is better
  • 1.0 is good, > 2.0 is excellent

Expectancy

Expectancy = (Win Rate × Avg Win) - (Loss Rate × Avg Loss)

A positive value = a profitable strategy

Consecutive Losses

  • The maximum number of losing trades in a row
  • Important for psychological resilience
  • More than 10-15 in a row → an unstable strategy

Conclusion

Testing EAs in the Strategy Tester is both an art and a science. Follow these recommendations:

  1. ✅ Test at least 1-2 years in “Every tick” mode
  2. ✅ Analyze key metrics: Profit Factor, Drawdown, Win Rate
  3. ✅ Examine the balance curve, as well as the figures
  4. ✅ Avoid overfitting: use Forward Testing
  5. ✅ Always test on demo for 2-4 weeks before trading live

Remember: tester results ≠ a guarantee of future profits. The market keeps changing, and even the best strategy can stop working. Always use risk management and never invest more than you are prepared to lose.


Recommended articles:

Download EAs for testing:


🤖 Recommended trading robots

Put what you have learned into practice with our free EAs:

  • Free MT4 expert advisors - a catalog of vetted trading robots
  • All files have been tested and are ready to use
  • Step-by-step installation and setup instructions are included

Popular EAs:

Share this article:

Comments (0)

Sign in to leave a comment

No comments yet

Be the first to leave a comment!

More EA guides and tests

EA reviews, demo trading results and MQL5 notes.

All blog articles