How to Backtest an EA in MetaTrader 5: An Honest Step-by-Step Guide
A backtest runs an Expert Advisor (EA) on past prices to see how it would have traded. Done well, it is one of the best tools a trader has. Done badly, it is the most convincing way to fool yourself. This guide shows how to run a backtest in MetaTrader 5's Strategy Tester, how to read the report, and the checks that separate an honest test from a fantasy.
Key takeaways
- Use "Every tick based on real ticks" for final results. Quicker modes can be wildly wrong for EAs that trade inside a candle.
- Add realistic costs: variable spreads, commission and some slippage. Free demo data often has no commission.
- Always keep an unseen (out-of-sample) period. Expect results there to be worse than in the period you tuned on.
- Read drawdown, losing months and profit factor, not just net profit.
- A backtest is evidence, not proof. Follow it with weeks or months of demo or cent-account forward testing.
What a backtest can and can't tell you
A backtest answers one question: if this EA, with these settings, had run on these prices, with these costs, what would have happened? It can show you how often the EA trades, how big its wins and losses are, how deep its drawdowns go, and whether a rule makes sense at all.
It can't tell you the future. Markets change, and an EA tuned to the past can fit noise rather than a real pattern. The goal isn't to find the settings with the highest past profit. It's to find out whether there is any real, robust edge after costs.
Step 1: Open the Strategy Tester and choose your settings
- In MT5, open View > Strategy Tester (or press Ctrl+R).
- On the Settings tab, choose Expert, then the EA from the list.
- Pick the symbol (for example XAUUSD) and timeframe the EA is designed for (for example M15).
- Set the date range. Use a long period with different market conditions: rising, falling and sideways.
- Set Forward to 1/3 or 1/4 if you want MT5 to keep part of the period aside as an unseen test (more on this below).
- Choose Delays. "Zero latency, ideal execution" flatters fast strategies; a random or fixed delay is more realistic.
- Choose Modelling: "Every tick based on real ticks" for final results.
- Set the deposit, account currency and leverage to match the account you will actually use.
- On the Inputs tab, load the EA's preset (.set file) or enter the settings. Make sure Optimization is off for a single test.
- Click Start.
Step 2: Pick the right modelling mode
The modelling mode decides how MT5 creates price movement inside each candle. This is the single most important setting.
| Mode | How it works | Use it for |
|---|---|---|
| Every tick based on real ticks | Uses the broker's recorded ticks, with spreads that change within each minute. | Final results. The most realistic. |
| Every tick | Generates ticks from 1-minute bars with a fixed spread per bar. | Testing when real ticks aren't available. Check results against real ticks. |
| 1 minute OHLC | Only the open, high, low and close of each 1-minute bar. | Quick screening of simple EAs only. |
| Open prices only | Only the open of each bar on the test timeframe. | Very fast rough checks of EAs that act only at bar open. |
| Math calculations | No price data at all. | Maths and optimisation tasks, not trading tests. |
After a test, check History Quality in the report. 100% means every minute had real tick data. Lower numbers mean MT5 filled gaps with generated ticks. For example, on the demo server we use, real gold ticks only start in late May 2025, so tests before then show a lower quality and should be treated as rough.
Step 3: Make the costs realistic
Most backtests look better than live trading because the costs are too low. Before trusting any result:
- Spreads: real-tick mode uses the recorded spreads from that server. Your broker's spreads may be wider, especially at rollover and news.
- Commission: many demo servers charge none. If your live account charges, say, $7 per lot round turn, include it. Otherwise subtract it from the results yourself.
- Swap: check that swaps are applied, especially for EAs that hold trades overnight or over Wednesdays.
- Slippage: add a delay setting, and treat results that depend on perfect fills with suspicion.
Adding commission to a report by hand
A test shows net profit of $2,400 on 600 trades with an average size of 0.20 lot, on a server that charged no commission. Your account charges $7 per lot round turn.
See spreads, commissions and swaps for more on costs.
Step 4: Read the report properly
After the test, open the Backtest tab (right-click for an HTML report). Here are the numbers that matter most:
| Number | What it means | What to look for |
|---|---|---|
| Total net profit | Profit after all trades, minus costs included in the test. | Positive after realistic costs. Not the only thing that matters. |
| Profit factor | Gross profit ÷ gross loss. | Above 1.0 means profitable. Below about 1.2 is fragile once real costs are added. |
| Expected payoff | Average profit per trade. | Compare it with your cost per trade. If costs are a large share, beware. |
| Maximal drawdown (balance and equity) | The biggest drop from a high, in money and %. Equity includes open trades. | Equity drawdown is the honest one for grids and baskets. |
| Total trades | How many trades the test made. | Hundreds give more reliable statistics than dozens. |
| Consecutive losses | The longest losing streak. | Could you sit through it with real money? |
| History quality | How much real tick data was used. | Aim for close to 100% on your final tests. |
Working out profit factor and expected payoff
A report shows gross profit $6,000, gross loss $4,800 and 400 trades.
Also look at the monthly results and the equity chart. Are profits spread across many months, or do one or two months make all the money? A strategy that only worked in one unusual month is not reliable.
Step 5: Keep an unseen period (out-of-sample)
If you change settings until the backtest looks good, you are fitting the EA to the past. The cure is to split the data:
- In-sample (tuning) period: where you choose settings.
- Out-of-sample (unseen) period: a later period you don't touch until the settings are final. Run it once.
MT5's Forward setting does this automatically during optimisation, keeping the last part of the period aside. You can also do it by hand with two date ranges.
Step 6: Forward test on a demo or cent account
The final check is live prices. Run the EA on a demo or cent account for at least several weeks, ideally a few months, and compare it with the backtest over the same period: number of trades, average win and loss, drawdown and spreads paid. If live results are much worse, find out why before you risk more. See demo vs cent vs standard accounts.
Going deeper: notes for experienced traders
- Walk-forward analysis. Repeat tune-then-test across rolling windows. Stable parameters across windows are a good sign; jumping parameters are not.
- Stress the costs. Re-run with spreads 50% wider and extra slippage. Note how much profit survives.
- Monte Carlo on trades. Shuffle the order of trades thousands of times to see the range of possible drawdowns. The backtest's drawdown is only one path.
- Count your tries. The more variants you test, the more likely the best one is luck. Write down how many combinations you tried.
- Pass every input explicitly. MT5 can silently reuse inputs from a previous run. Load the .set file each time, and keep the report with the exact settings.
- Watch for look-ahead bias. An EA that uses the current bar's close or high before the bar has finished will look far better in testing than live.
Common mistakes
- Using fast modelling modes for final results. "Open prices only" and "1 minute OHLC" can be very wrong for EAs that trade within a candle.
- Leaving out commission. Demo servers often charge none. Live accounts often do.
- Testing only a short or one-sided period. A rising-gold period makes most buy strategies look good.
- Choosing the single best optimisation result. It's usually the luckiest. Look for stable ranges of settings.
- Ignoring equity drawdown. Grid and basket EAs can hide large open losses that balance drawdown doesn't show.
- Skipping the forward test. Live prices, fills and costs are the final exam.
Printable checklist
- Modelling is set to "Every tick based on real ticks".
- History quality is close to 100% for the period I'm relying on.
- Deposit, currency and leverage match my real account.
- Commission and realistic delays are included (or subtracted by hand).
- The test covers rising, falling and sideways markets.
- I kept an unseen period and ran it only once with final settings.
- I checked profit factor, equity drawdown, losing streak and monthly results, not just net profit.
- I forward tested on demo or cent for weeks before going further.
Frequently asked questions
Which modelling mode should I use in MT5?
Use "Every tick based on real ticks" for any result you rely on. Faster modes are fine for quick screening of simple strategies, but always confirm on real ticks.
How many years should I backtest?
As long as you have good data that covers different market conditions. Two years of real-tick data with an unseen period at the end is a reasonable minimum for most intraday EAs; longer is better where data quality allows.
What is a good profit factor?
Above 1.0 is profitable in the test. Many traders look for 1.3 or more after realistic costs, because live trading is usually worse. Very high values on few trades often mean overfitting.
What is history quality?
It shows how much of the test used real tick data. 100% means every minute had real ticks. Lower values mean MT5 generated ticks to fill gaps, so results are less reliable.
Why are my live results worse than my backtest?
Common reasons are higher costs, slippage, different broker prices, and settings that were fitted to the past. That's why an unseen period and forward testing matter.
Can a backtest prove an EA will make money?
No. It can only show how the EA would have behaved on past data with the assumptions used. Most EAs lose money in the long run, so treat any backtest as one piece of evidence.
Sources and further reading
- MetaTrader 5 Help: Strategy Tester
- MetaTrader 5 Help: real and generated ticks (modelling modes)
- MetaTrader 5 Help: testing report
- Pips & Gold: What is an EA?
This guide is general education, not financial advice. Broker terms differ; always check your own broker's contract specifications.