How to Backtest an EA in the MT5 Strategy Tester (Step by Step)
By the Victoryalgo team · · 7 min read
You have an Expert Advisor (EA) for MetaTrader 5. Before it trades a live account, you should test it on past prices. This is called backtesting, and MT5 has a built-in tool for it: the Strategy Tester.
This guide shows you how to use it step by step. If you do not have an EA yet, start with How to Turn Your Trading Strategy Into an MT5 EA.
What a Backtest Can and Cannot Tell You
A backtest shows how your rules would have acted on past prices. It is very useful for finding coding errors.
But it is not a forecast. Real trading also has slippage, wider spreads and delays that a test may not fully copy. Treat every number in the report as a test statistic, not a promise.
Step 1: Open the Strategy Tester
In MT5, open the tester from the View menu, or press Ctrl+R. On the Settings tab, choose:
- Expert: the EA you want to test.
- Symbol: the market, such as EURUSD. Use the exact symbol name your broker uses, including any suffix.
- Timeframe: the chart period the EA was built for, such as H1.
- Date: the start and end dates. Choose a long period with different market conditions, not only a few good weeks.
Step 2: Choose the Modelling Mode
The modelling mode decides how MT5 builds the price movement inside each candle. It has a big effect on how realistic the test is.
- Every tick based on real ticks: uses real tick history from your broker, where it is available. It is usually the most realistic mode, and the slowest.
- Every tick: creates ticks from one-minute data. These ticks are generated, so they only estimate real movement.
- 1 minute OHLC: uses only the open, high, low and close of each one-minute bar. Faster, but less exact.
- Open prices only: very fast, but it only suits EAs that act once per new candle.
A simple approach is to use a fast mode for rough checks, then run the final test with real ticks.
Step 3: Set Deposit, Leverage, Spread and Delay
- Deposit and currency: use values close to the account you plan to use. A very large test deposit can hide risk problems.
- Leverage: use the same leverage as your real account. It affects margin and whether a trade can open.
- Delays: the default is "Zero latency, ideal execution". You can also choose a random or fixed delay. A delay copies the time between sending an order and the broker filling it.
In real-tick mode, MT5 uses the spread recorded with each tick. Other modes use spread data stored with the price history. Real spreads can be wider at news times, so test several periods if your strategy is sensitive to spread.
Also check whether commission and swap are included. This depends on your broker's account settings. If they are missing, the test does not show your full costs.
Step 4: Read the Report
Click Start. When the test ends, MT5 shows a report and a balance graph. These are the main numbers:
- Total trades: how many trades the EA made. A small number says very little, because a few lucky trades can change everything.
- Profit factor: gross profit divided by gross loss. Above 1 means winning trades added up to more than losing trades in this test.
- Expected payoff: the average result per trade in the test period.
- Drawdown: the largest drop from a high point. Balance drawdown counts closed trades. Equity drawdown also counts open trades, so it is often more useful.
- Maximum consecutive losses: the longest losing streak in the test.
Also look at History quality. A low value means gaps in the data. Then open the Journal tab and look for errors such as "invalid stops" or "not enough money". These often point to a coding problem or a wrong setting.
Remember, these statistics describe one test on past data, not the future.
Step 5: Watch Trades in Visual Mode
Tick Visual mode with the display of charts, indicators and trades and start again. MT5 replays the market on a chart. You can change the speed and pause on each trade.
Check that each entry, stop loss, take profit and lot size matches your rules. This is the easiest way to find a rule that was coded differently than you meant. If something looks wrong, send screenshots with the date and time to your developer.
Step 6: Simple Optimisation
Optimisation means testing many input values to see how results change. For example, a stop loss from 20 to 60 pips in steps of 10.
- Open the Inputs tab and tick the setting you want to test.
- Enter the Start, Step and Stop values.
- On the Settings tab, choose a method. "Slow complete algorithm" tests every combination. "Fast genetic based algorithm" tests a smart sample, which is quicker with many inputs.
- Choose a criterion, such as maximum balance, and click Start.
The Danger of Over-Optimisation
If you test enough values, some will look great on past data by pure chance. This is called curve fitting or over-optimisation. Such settings fit old prices too closely and may behave very differently on new data.
Warning signs:
- The best result stands alone, and nearby values give much worse results.
- Many inputs were optimised at once.
- The good results come from only a few trades.
- The results fall apart on a different date range.
The Forward option can help. It keeps part of your date range aside. MT5 optimises on the first part, then tests the chosen values on the part it did not see.
Step 7: Forward Test on a Demo Account
Next, run the EA on a demo account with live prices. This forward test shows real spreads and real order execution.
Let it take a fair number of trades, then compare them with a backtest of the same days. Small differences are normal. Big differences often mean a rule needs fixing.
A bot follows your rules, but results depend on your strategy and the market. You can lose money with any EA, so always test on demo before a live account.
Common Backtesting Mistakes
- Testing a short period. A few good months can hide weak periods.
- Using "Open prices only" for the wrong EA. If the EA acts inside the candle, results will be wrong.
- Ignoring costs. Missing spread, commission or swap makes the test look better than real trading.
- Only testing with zero delay. Try a delay setting too.
- Testing the wrong account type. Hedging and netting accounts handle positions differently. See MT4 vs MT5: Which Is Better for Your Expert Advisor?
- Changing the rules after every test. Each change fits the EA more closely to the past.
Testing Other Kinds of Bots
The Strategy Tester only runs MQL5 programs. For Pine Script, read Can You Convert a TradingView Strategy to MT5? For funded accounts, see Prop Firm EA: How to Code Daily Drawdown and Max Loss Rules. Still choosing a language? Read Python vs MQL5: Which Is Better for Your Trading Bot?
Get Your Strategy Coded
Victoryalgo codes traders' own strategies through our MT5 EA development and MT4 EA development services.
Have a strategy you want to test as an EA? Send us your strategy on WhatsApp for a free consultation. The Victoryalgo team will read your rules and explain how they can be coded.
Victoryalgo is a software development company, not registered with SEBI or any financial regulator. This guide is general education about software, not investment advice. Forex and CFD trading is high risk. Indian residents may trade forex only through RBI-authorised channels.
Frequently Asked Questions
Which modelling mode should I use in the MT5 Strategy Tester?
Every tick based on real ticks is usually the most realistic choice when your broker provides tick history. Faster modes are fine for quick checks, but Open prices only is suitable just for EAs that act once per new candle.
Does a good backtest mean the EA will work in live trading?
No. A backtest only shows how the rules acted on past prices. Live results depend on your strategy and the market, and you can lose money, so forward test on a demo account first.
What is over-optimisation?
It means tuning settings so closely to past data that they fit old prices by chance. Such settings may behave very differently on new data.
How long should I forward test an EA on a demo account?
There is no fixed rule. Run it long enough to see a fair number of trades in different market conditions, and compare them with the backtest.
More Guides
Want your strategy coded?
Send your rules on WhatsApp. Free consultation, clear quote.
WhatsApp Your Strategy