50% off Pro's first year — codePRO50

9 min readBacktestingMetaTrader 5

MT5 Backtesting Software: How to Test a Strategy Properly

A practical guide to backtesting software for MetaTrader 5 — data quality, spread and commission modelling, sample size, and out-of-sample testing.

Backtesting is the cheapest way to find out that an idea does not work. That is its real value. Most traders treat a backtest as evidence that a strategy will make money, which is exactly backwards — a backtest is evidence that a strategy would have made money, on one specific slice of history, under a specific set of assumptions about cost and execution.

Get those assumptions wrong and the number at the end of the report is fiction. This guide covers what backtesting software for MetaTrader 5 actually needs to model, and how to read a result honestly.

What a backtest can and cannot tell you

A backtest can tell you three useful things:

  • Whether your rules are internally consistent and actually produce trades
  • How the strategy behaved across different market conditions in the sample
  • Roughly what drawdown you would have had to sit through

It cannot tell you the future return. It cannot tell you the strategy is "profitable" in any forward-looking sense. And it is very easily manipulated — accidentally — into showing a beautiful equity curve that has no chance of surviving contact with a live account.

The gap between backtest and live performance almost always comes from one of four places: cost modelling, data quality, sample size, or overfitting. Handle those four and your expectations get a lot more realistic.

Start with data quality

MetaTrader 5's built-in Strategy Tester offers several modelling modes, and the difference between them is not cosmetic.

Every tick based on real ticks uses the actual tick history your broker supplies. This is the most faithful option and the slowest. If your strategy touches intrabar behaviour at all — stop losses, take profits, trailing stops, anything triggered inside a candle — this is the mode that matters.

Every tick generates synthetic ticks from M1 bars using an interpolation algorithm. It is faster, and fine for slow strategies that only act on bar close, but it invents intrabar price paths that never happened. If your stop and target are both inside the same candle, the tester has to guess which one you hit first. That guess can flatter you badly.

1 minute OHLC and Open prices only are faster still and correspondingly cruder. Treat results from these as a smoke test, not a result.

There is a second data problem that has nothing to do with modelling mode: your broker's history is not universal. Two brokers will show you different spreads, different session boundaries, sometimes different candle counts on the same instrument. A strategy tuned to one broker's data can behave differently on another. If you intend to trade live with a specific broker, backtest on that broker's data.

Model your costs honestly

This is where most retail backtests fall apart, and it is entirely avoidable.

Spread. The Strategy Tester can use a fixed spread or the historical spread from the tick data. Fixed spread at the broker's advertised "typical" number is optimistic, because the advertised number is not what you get during news, at the session open, or at the rollover. If your average trade nets 8 pips and you modelled 0.6 pips of spread when the real average was 1.4, you have quietly deleted a tenth of your edge. For strategies scalping a few pips, spread modelling is the single most important input in the whole test.

Commission. Raw-spread accounts charge per lot per side. It is a fixed, knowable cost and it is astonishing how often it gets left out entirely. On a high-frequency strategy, commission can exceed spread as a cost centre.

Swap. If you hold overnight, you pay or receive swap. For a strategy holding positions for days, swap can be the difference between profit and loss over a year, and it is asymmetric — long and short are charged differently on the same pair.

Slippage. The tester generally assumes your order fills at the price you asked for. Live, it does not, particularly on market orders during fast conditions. There is no perfect way to model this; the pragmatic approach is to add a pessimistic buffer to your cost assumptions and see whether the strategy still works. If a strategy only survives with zero slippage, it does not survive.

A useful discipline: run the test twice, once with your realistic cost assumptions and once with costs inflated by 50%. If the second run turns a good strategy into a bad one, your edge is thinner than you think.

Sample size is not negotiable

A strategy with 30 trades has told you almost nothing. Random noise produces 30-trade winning streaks routinely.

There is no magic threshold, but as a rough guide: below 100 trades you are looking at an anecdote; 300 or more starts to be a sample you can reason about; and what matters more than the raw count is whether those trades span different market regimes. A trend-following system tested only across 2020-2021 learned one lesson: buy dips, they always recover. That lesson was expensive for anyone who carried it into a ranging market.

Deliberately include periods you expect to be hostile to your strategy. A mean-reversion system should be tested through a strong trend. A breakout system should be tested through a long chop. If it only works in its favourite weather, you now know its actual risk profile — which is genuinely useful information, not a reason to discard it.

Reserve out-of-sample data before you start

This is the step that separates a real test from an elaborate exercise in self-deception.

Split your history before you begin. Develop, tune and fiddle on the in-sample portion — say the first 70% — and do not look at the remaining 30% at all. When you are finished tuning, run once on the out-of-sample portion. That single run is your honest estimate.

The moment you tune based on out-of-sample results, they stop being out-of-sample. You have folded that data into your development set, and you need fresh data to get an honest read again.

Walk-forward analysis formalises this: optimise on a window, test on the window immediately after it, roll forward, repeat. It is more work, and it is a much better predictor of live behaviour than a single optimisation across all of history.

Read the report beyond net profit

Net profit is the least informative number in the report. More useful:

  • Maximum drawdown, in both money and percent — this is the number that decides whether you can actually run the strategy, because it is the pain you must tolerate without switching it off
  • Longest losing streak — psychologically this is often harder than drawdown depth
  • Profit factor — gross profit divided by gross loss. Above 1.3 is respectable; above 3.0 on a small sample usually means overfitting rather than genius
  • Trade distribution — if removing your three best trades turns the strategy unprofitable, you do not have a strategy, you have three lucky trades
  • Time in market — a system that is flat 95% of the time carries very different risk to one that is always exposed

Where dedicated backtesting software helps

MT5's Strategy Tester is capable, but it tests Expert Advisors — which means your idea has to exist as MQL5 code before you can test it at all. For most traders that is the bottleneck: the strategy lives in their head, and turning it into a compiled EA is a programming project that has to be repeated for every variation they want to try.

Dedicated backtesting software closes that loop. Building rules visually means the distance between "I wonder if" and a tested result is minutes rather than an evening of debugging. That matters because good strategy development is mostly iteration — testing twenty variations of an idea, most of which fail. If each variation costs an hour of coding, you will test three and settle. If each costs two minutes, you will actually explore the space.

Raw Edge handles most of this for you. You drag indicators, structural patterns and price action into Long and Short condition chains, and the backtest runs on your broker's own historical prices using their measured spread applied per bar — not one average for the whole test — so a fill in the thin overnight session is charged the wider spread that actually existed, rollover spike included. Measured slippage and real overnight swap are modelled too. You can override the spread with a fixed value if you want to stress-test.

The one cost you must set yourself is commission: it defaults to a Zero profile, and if your broker charges commission and you leave it there, every backtest will flatter itself. Set what your broker actually charges — per lot per side, a percentage, or in pips — and save it as a named profile so it is one click next time.

The Trade Optimiser then runs hundreds of variations across stop distance, take profit ratios, trailing and lot size, with walk-forward validation built in and results ranked by Sharpe ratio, profit factor and maximum drawdown — so the winner is not simply whichever variation fits your sample best.

A workable process

  1. Define the rules precisely, in writing, before you touch software — entry, exit, stop, target, position size, and what happens if two signals conflict
  2. Split your data and set the out-of-sample portion aside
  3. Run a first test on realistic costs with a fast modelling mode, purely to check the rules produce sane trades
  4. Re-run on real-tick data with honest spread, commission and swap
  5. Iterate on the in-sample data only
  6. Test once on out-of-sample data
  7. Forward test on a demo account for long enough to see real spreads and real fills
  8. Go live small

Steps 7 and 8 are not optional. A backtest is a filter for bad ideas, not a certificate for good ones. Its job is to stop you risking money on something that was never going to work — and it does that job extremely well, provided you let it deliver bad news.

Test it before you trade it

Raw Edge lets you build strategies visually, backtest them with realistic spread and commission, and deploy the same logic straight to MetaTrader 5.

See pricing

More reading