New tools are launching soon. Open any tool and choose Notify me to hear first.Chat with us on Telegram

How to backtest an EA in the MT4 and MT5 strategy tester

Run a reliable backtest of an expert advisor in the MetaTrader strategy tester: modelling modes, tick data, spreads, date ranges and how to read the report.

Testing and choosing tools12 min readUpdated

A backtest runs an expert advisor over past prices to show how it would have traded. MetaTrader 4 and MetaTrader 5 both include a strategy tester for the job, and both will produce a polished report from poor inputs without complaint. This guide covers the settings that decide whether a backtest means anything, how to run one on each platform and how to read the numbers that come out.

What a backtest can and can't tell you

A backtest answers one narrow question: if these rules had traded these prices, with these costs, what would have happened? That answer is useful for three jobs. It confirms the EA does what its documentation says. It shows how the EA behaves in conditions you can name, such as a strong trend or a quiet summer. And it gives you a first estimate of drawdown, the number you need to size the EA.

It can't tell you what happens next. The tester fills orders at the prices in its history, with no requotes, no broker outages and, unless you add them, no delays. Spreads, slippage and swap are approximations. Treat a backtest as a filter. A poor result is a strong reason to reject an EA. A good result is only a reason to keep testing.

Get good history data first

The tester can only be as accurate as the prices it reads, and this is where the two platforms differ most. Our MT4 vs MT5 guide covers the wider differences.

History in MT4

MT4 tests from bar history stored on your computer. It builds ticks from one-minute bars, so it needs complete M1 history for the whole test period, not just the timeframe you test on.

  1. Open Tools > Options > Charts, raise Max bars in history and Max bars in chart to a large number, and restart MT4.
  2. Open Tools > History Center (F2), select the symbol, choose 1 Minute (M1) and click Download.
  3. Check the date range you want is actually covered before you test it.

Every MT4 report shows a Modelling quality percentage. It measures how completely the tester could rebuild price movement from the data available. Every tick on complete M1 history tops out at around 90%. Higher figures need imported tick data and third-party tools. The history a broker loads by default often has gaps or covers only recent months, which drags the figure far lower. Also check Mismatched charts errors in the report. Anything above zero means the timeframes in your history disagree and the data needs repairing.

History in MT5

MT5 downloads history from your broker's server when a test starts, including recorded tick history where the broker keeps it. The report shows a History Quality percentage. A test on complete real ticks shows close to 100%. Where real ticks are missing, the tester generates them from minute bars and the figure drops.

On either platform, test on data from the broker you plan to trade with when you can. Server time zones differ, and a session-based EA trades different hours on data from a server two hours ahead.

Modeling modes compared

The modeling mode decides how the tester moves price inside each bar. Accurate modes are slower. Fast modes skip information that many EAs depend on.

ModePlatformHow price movesBest for
Every tickMT4Generates ticks inside each bar from the smallest timeframe available, usually M1.Most EAs, especially those with tight stops, trailing stops or entries inside a bar.
Control pointsMT4Builds each bar from a few points taken from the next lower timeframe.Quick rough checks. Results can differ a lot from Every tick.
Open prices onlyMT4 and MT5Uses only the opening price of each bar on the test timeframe.Fast optimization of EAs that act only when a new bar opens.
Every tick based on real ticksMT5Replays the broker's recorded ticks, with their real spreads.Final tests, and anything sensitive to spread or execution, such as scalpers.
Every tickMT5Generates ticks from M1 bars.General testing when real ticks aren't available.
1 minute OHLCMT5Uses the open, high, low and close of each M1 bar: four prices per minute.Faster tests of EAs that don't depend on tick-by-tick movement.
Math calculationsMT5Loads no price history at all.Pure calculations run through the optimizer, not normal EA tests.

A quick check tells you whether a fast mode is safe for a given EA. Run the same settings once in Open prices only and once in a tick mode. If the results are close, the EA really does act only on new bars and the fast mode is fine for optimization. If they diverge, the EA reacts inside bars and only the tick-based result counts.

Run a backtest in MT4

  1. Open the tester with View > Strategy Tester or press Ctrl+R. A panel opens at the bottom of the terminal.
  2. Choose Expert Advisor in the first drop-down and pick your EA. If it isn't listed, check it's in MQL4/Experts; our installation guide shows where files go.
  3. Set Symbol and Period to the ones in the EA's documentation.
  4. Set Model to Every tick.
  5. Tick Use date and enter the From and To dates. Cover several years if your history allows.
  6. Set Spread. Current uses the spread at the moment you press Start for the whole test, which can be very wide on a weekend. Type a fixed value instead. It is in points, so on a five-digit broker 10 points is 1 pip. Use your account's typical spread or slightly worse.
  7. Click Expert properties. On the Testing tab, set the initial deposit and currency and whether the EA may trade long, short or both. On the Inputs tab, load the developer's .set file or enter the settings you plan to trade.
  8. Tick Visual mode if you want to watch trades appear on a chart, then press Start.

MT4's tester uses the leverage of the account you are logged into and has no commission field. If your account pays commission, add its cost to the spread. On EURUSD with a USD account, a commission of $7 per lot round turn works out to 0.7 pips, or 7 points.

Run a backtest in MT5

  1. Open View > Strategy Tester or press Ctrl+R, then go to the Settings tab.
  2. Choose the EA under Expert, then the symbol and timeframe.
  3. Set Date to a custom period and pick the range.
  4. Leave Forward set to No for a first test.
  5. Set Delays. Zero latency is the ideal case. A random or fixed delay is closer to live execution.
  6. Set Modelling to Every tick based on real ticks if your broker provides tick history.
  7. Enter the Deposit and its currency, and set Leverage to match your live account.
  8. Leave Optimization disabled, set the EA's inputs on the Inputs tab, tick Visual mode if you want it, and press Start.

MT5 has no spread box. Spreads come from the history: real ticks carry the spread at each moment, and the generated modes use the spread stored with each minute bar. To test a wider spread, some traders copy the symbol into a custom symbol with a fixed, wider spread. After a test, check the commission column in the deals list. If it shows zero but your account pays commission, the result is too optimistic, so subtract the cost per trade or widen the spread to cover it.

MT5 can do several things MT4 can't. It tests EAs that trade several symbols at once, keeping their prices in sync. It splits work across your processor cores as local agents, and for large optimizations it can add agents on other computers or rented capacity from the MQL5 Cloud Network. It also has built-in forward testing and a genetic optimizer, both covered below.

How to read the report

Both testers end with a report and a graph. Look at the graph first. A balance line that climbs in neat steps while the equity line keeps dipping well below it means trades are being held open in deep loss. Then work through the figures:

FigureWhat it meansWhat to look for
Total net profitGross profit minus gross loss, after the costs the tester applied.Means little on its own. Always compare it with the drawdown.
Profit factorGross profit divided by gross loss.Above 1 is profitable on this data. A very high value on few trades often points to overfitting.
Expected payoffThe average profit per trade.It should be clearly larger than the spread and commission of a single trade.
Maximal and relative drawdownThe largest fall from a peak, in money and as a percentage. MT5 lists it separately for balance and equity.Equity drawdown includes floating losses on open trades and is the one that matters.
Total tradesThe number of closed trades.Hundreds of trades say far more than a few dozen.
Profit tradesThe share of trades that closed in profit, or win rate.Read it next to the average win and average loss. A high win rate with a much larger average loss is fragile.
Maximum consecutive lossesThe longest losing streak and what it cost.Expect a longer streak live, and make sure you could sit through it.
Recovery factorNet profit divided by maximal drawdown.Higher means more profit for the pain taken. Low values mean drawdowns dominate the result.
Sharpe ratio (MT5)Return relative to how much returns vary.Useful for comparing settings of the same EA, less so across very different EAs.

Drawdown costs more to recover than it takes to lose. The drawdown calculator shows the gain needed to climb back from the figure in your report. For a full checklist of what makes a result trustworthy, read how to evaluate an expert advisor.

Avoid overfitting with out-of-sample tests

Optimization runs an EA many times with different inputs and ranks the results. With enough combinations, some will fit the past closely by pure chance. That is overfitting, also called curve fitting, and it is the most common reason a great backtest fails live.

Out-of-sample testing

Split your history in two. Optimize on the first part, called in-sample, then run the chosen settings unchanged on the later part, called out-of-sample. MT5 does this for you: set Forward to 1/2, 1/3, 1/4 or a custom date, and the tester reports the forward period separately for every pass. In MT4, run the two date ranges by hand.

Walk-forward testing

Walk-forward testing repeats that split through time. Optimize on, say, two years, test on the next six months, then move both windows forward and repeat. Joined together, the out-of-sample pieces form a result built only from data the settings had never seen. Neither tester automates the full process, so traders run the windows by hand or use external tools.

Signs of an overfit result

  • The best settings sit on a sharp peak: moving one input a small step turns profit into loss. Robust settings sit on a broad plateau where neighboring values also do well.
  • The EA has many inputs compared with its number of trades.
  • Results are excellent in-sample and flat or negative out-of-sample.
  • Oddly precise values, such as a 37-pip stop with a 13-period filter, work on one symbol and nowhere else.

MT5's Fast genetic based algorithm searches huge input ranges quickly by testing only promising combinations. It finds good fits faster, which means it also finds overfit ones faster. That makes out-of-sample checks more important, not less.

Common backtesting mistakes

  • The wrong modeling mode. Testing an EA with tight stops or trailing logic in Open prices only or Control points.
  • Unrealistic spreads. Using Current on a weekend, or a fixed spread of 0 or 1 point that no live account gets.
  • Short date ranges. A few months may hold only one kind of market. Include trending, ranging, quiet and volatile periods.
  • Ignoring swap. EAs that hold trades for days pay or earn swap every night, and it adds up.
  • Mixed-up comparisons. Comparing reports with different deposits or lot settings. A compounding EA's profit grows with the starting deposit.
  • Trusting a smooth curve. Grid and martingale EAs often produce near-perfect balance lines that hide deep floating losses. Our grid and martingale guide explains why.
  • Forgetting live conditions. Live trading adds slippage, requotes and downtime. Running the EA on a forex VPS reduces downtime, but the rest still widens the gap between test and account.

Once a backtest survives realistic costs, several periods and an out-of-sample check, the next step is a demo forward test with your own broker. That is where the simulation meets real fills.

Frequently asked questions

What is a good modelling quality in MT4?

With complete one-minute history and the Every tick model, MT4 tops out at around 90%. Higher figures need imported tick data. Tests far below that, or with mismatched chart errors, are unreliable for EAs with tight stops or logic that acts inside a bar.

Which MT5 modelling mode should I use?

Use Every tick based on real ticks for final tests, because it replays recorded prices and spreads. Every tick and 1 minute OHLC are fine for faster checks, and Open prices only suits optimizing EAs that act only when a new bar opens.

How many years should I backtest an EA?

Long enough to include hundreds of trades and several kinds of market, such as strong trends, long ranges and volatile periods. For many EAs that means several years. A test of a few months rarely says much.

Why are my live results worse than the backtest?

Live trading adds slippage, changing spreads, commission, swap, requotes and downtime that a backtest only approximates. Overfit settings and a market that has changed since the test period widen the gap further.

Can I backtest an MT4 EA in MT5?

No. MT4 EAs are .ex4 files and only run in the MT4 strategy tester. To test in MT5 you need an .ex5 version of the EA built for MT5.

Educational information only, not financial advice. Trading forex and CFDs on margin carries a high risk of losing money. Read our risk warning.

Hear about new tools first

One short email when a tool launches or a big update ships.