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.
- Open
Tools > Options > Charts, raiseMax bars in historyandMax bars in chartto a large number, and restart MT4. - Open
Tools > History Center(F2), select the symbol, choose1 Minute (M1)and clickDownload. - 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.
| Mode | Platform | How price moves | Best for |
|---|---|---|---|
| Every tick | MT4 | Generates 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 points | MT4 | Builds 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 only | MT4 and MT5 | Uses 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 ticks | MT5 | Replays the broker's recorded ticks, with their real spreads. | Final tests, and anything sensitive to spread or execution, such as scalpers. |
| Every tick | MT5 | Generates ticks from M1 bars. | General testing when real ticks aren't available. |
| 1 minute OHLC | MT5 | Uses 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 calculations | MT5 | Loads 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
- Open the tester with
View > Strategy Testeror press Ctrl+R. A panel opens at the bottom of the terminal. - Choose
Expert Advisorin the first drop-down and pick your EA. If it isn't listed, check it's inMQL4/Experts; our installation guide shows where files go. - Set
SymbolandPeriodto the ones in the EA's documentation. - Set
ModeltoEvery tick. - Tick
Use dateand enter theFromandTodates. Cover several years if your history allows. - Set
Spread.Currentuses 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. - Click
Expert properties. On theTestingtab, set the initial deposit and currency and whether the EA may trade long, short or both. On theInputstab, load the developer's.setfile or enter the settings you plan to trade. - Tick
Visual modeif you want to watch trades appear on a chart, then pressStart.
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
- Open
View > Strategy Testeror press Ctrl+R, then go to theSettingstab. - Choose the EA under
Expert, then the symbol and timeframe. - Set
Dateto a custom period and pick the range. - Leave
Forwardset toNofor a first test. - Set
Delays. Zero latency is the ideal case. A random or fixed delay is closer to live execution. - Set
ModellingtoEvery tick based on real ticksif your broker provides tick history. - Enter the
Depositand its currency, and setLeverageto match your live account. - Leave
Optimizationdisabled, set the EA's inputs on theInputstab, tickVisual modeif you want it, and pressStart.
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:
| Figure | What it means | What to look for |
|---|---|---|
| Total net profit | Gross profit minus gross loss, after the costs the tester applied. | Means little on its own. Always compare it with the drawdown. |
| Profit factor | Gross profit divided by gross loss. | Above 1 is profitable on this data. A very high value on few trades often points to overfitting. |
| Expected payoff | The average profit per trade. | It should be clearly larger than the spread and commission of a single trade. |
| Maximal and relative drawdown | The 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 trades | The number of closed trades. | Hundreds of trades say far more than a few dozen. |
| Profit trades | The 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 losses | The longest losing streak and what it cost. | Expect a longer streak live, and make sure you could sit through it. |
| Recovery factor | Net 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 onlyorControl points. - Unrealistic spreads. Using
Currenton 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.