Pips & GoldTrade smarter. Forex & gold.
Learn

How to Backtest an EA in MetaTrader 5: An Honest Step-by-Step Guide

Updated October 27, 2026 · By the Pips & Gold team

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.

By Pips & Gold teamLast updated October 21, 20268 min readLevel: Intermediate (beginners welcome)

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.

1Get gooddata2Set realisticcosts3Run onreal ticks4Read thereport5Test unseenperiod6Demo forwardtestAn honest backtest, step by stepSkip a step and the results will flatter the EA.
Each step removes a way the test could flatter the EA.

Step 1: Open the Strategy Tester and choose your settings

  1. In MT5, open View > Strategy Tester (or press Ctrl+R).
  2. On the Settings tab, choose Expert, then the EA from the list.
  3. Pick the symbol (for example XAUUSD) and timeframe the EA is designed for (for example M15).
  4. Set the date range. Use a long period with different market conditions: rising, falling and sideways.
  5. 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).
  6. Choose Delays. "Zero latency, ideal execution" flatters fast strategies; a random or fixed delay is more realistic.
  7. Choose Modelling: "Every tick based on real ticks" for final results.
  8. Set the deposit, account currency and leverage to match the account you will actually use.
  9. On the Inputs tab, load the EA's preset (.set file) or enter the settings. Make sure Optimization is off for a single test.
  10. Click Start.
Use the visual mode onceTick Visual mode for a short test to watch the EA trade on a chart. It's the easiest way to spot an EA that opens trades at the wrong times or ignores its own rules.

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.

ModeHow it worksUse it for
Every tick based on real ticksUses the broker's recorded ticks, with spreads that change within each minute.Final results. The most realistic.
Every tickGenerates 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 OHLCOnly the open, high, low and close of each 1-minute bar.Quick screening of simple EAs only.
Open prices onlyOnly the open of each bar on the test timeframe.Very fast rough checks of EAs that act only at bar open.
Math calculationsNo price data at all.Maths and optimisation tasks, not trading tests.
A real example of how wrong fast modes can beIn our own EA testing at Pips & Gold, one EA showed a profit of +251% in a quick "1 minute OHLC" test. The same EA on real ticks lost 99%. Since then, every result we publish uses real ticks only. If an EA uses tight stops, grids, trailing stops or scalping, fast modes can be badly misleading.

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.
Worked example

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.

Commission = 600 trades × 0.20 lot × $7 = $840 Adjusted net profit = $2,400 − $840 = $1,560 That's 35% less than the report showed.

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:

NumberWhat it meansWhat to look for
Total net profitProfit after all trades, minus costs included in the test.Positive after realistic costs. Not the only thing that matters.
Profit factorGross profit ÷ gross loss.Above 1.0 means profitable. Below about 1.2 is fragile once real costs are added.
Expected payoffAverage 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 tradesHow many trades the test made.Hundreds give more reliable statistics than dozens.
Consecutive lossesThe longest losing streak.Could you sit through it with real money?
History qualityHow much real tick data was used.Aim for close to 100% on your final tests.
Worked example

Working out profit factor and expected payoff

A report shows gross profit $6,000, gross loss $4,800 and 400 trades.

Net profit = $6,000 − $4,800 = $1,200 Profit factor = $6,000 ÷ $4,800 = 1.25 Expected payoff = $1,200 ÷ 400 = $3.00 per trade

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.
Tuning (in-sample): settings chosen hereUnseen (out-of-sample)flatter: the usual resultTime →Equity
Illustration only. In honest tests, results in the unseen period are usually weaker than in the tuning period.

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.

What honest results look likeIn our own testing of a gold EA, the Conservative preset averaged +1.67% a month in the tuning period but +0.71% a month in the unseen period. That drop is normal and is exactly why we show both. Be suspicious of any EA seller who only shows one smooth equity curve.
Optimisation trapsMT5's optimiser can test thousands of combinations. The best-looking one is often the luckiest, not the best. Prefer settings where nearby values also work (a "plateau"), and re-run the finalists individually. If a small change in one input destroys the result, the edge probably isn't real.

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

  1. 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.
  2. Leaving out commission. Demo servers often charge none. Live accounts often do.
  3. Testing only a short or one-sided period. A rising-gold period makes most buy strategies look good.
  4. Choosing the single best optimisation result. It's usually the luckiest. Look for stable ranges of settings.
  5. Ignoring equity drawdown. Grid and basket EAs can hide large open losses that balance drawdown doesn't show.
  6. 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.

Risk warning: most EAs lose money in the long runTrading forex and gold with leverage is high risk and you can lose all of your deposit. Most Expert Advisors do not make money over the long term. Every result shown here is a backtest on past prices, not live trading, and past results do not promise future results. Live results will be different because of spreads, commission, slippage and changing markets. This is not financial advice. Test on a demo account first and only trade money you can afford to lose. Full risk disclaimer.

Sources and further reading

This guide is general education, not financial advice. Broker terms differ; always check your own broker's contract specifications.