Python looked good, the MT5 tester said no: six cases from our lab

A look-ahead leak, a wrong spread, uncounted swap, missing broker bars: six candidates that looked good in Python and failed in the MT5 tester.

Written by: WICKVIPER Study ID: HISTORIA-08 Published: Updated:

Does not work

Short answer

Can I trust my own Python backtest, or do I need to confirm it in the broker's strategy tester?

Use Python to find and rank candidates, not to decide. In six documented cases a candidate that looked good in Python failed once it was run in the MT5 Strategy Tester. In four the tester exposed an error in the Python model (a look-ahead leak, an understated spread, uncounted swap, missing broker bars), in one we did not isolate the cause, and in one the rule simply did not hold out of sample.

Data
XAUUSD, US30, EURJPY and DE30 (DAX) CFDs from our broker
Period
cases recorded in September 2026; broker data from 2011
Sample
six candidates that passed our Python screens and were then run in the MT5 Strategy Tester
Costs
tester: spread bar by bar from the broker's history, swap in the broker's points; results at fixed test lot sizes

Key numbers

Trend filter with a leak
p 0.002 and 0.008 in Python, tester −906 USD gross
Gold scalper, one spread figure
Python +1.15 bp, tester −1.5 bp (−1,797 USD)
Swap Python did not count
gold −7,471 USD, US30 −9,131 USD
EURJPY, hour 0
109 trades in the tester vs 1,709 in Python

Where the idea comes from

A Python backtest is fast. You can test thousands of rule variants in an hour, and that speed is exactly why we use it. But a Python backtest is only as honest as its model of the market: the prices it sees, the round-trip costs it charges (spread, commission, swap) and the order in which it reads the data.

The broker's own strategy tester (in our case MetaTrader 5) is slower and less flexible, but it charges the spread bar by bar from the broker's history, books swap in the broker's own points, refuses orders the broker would not accept, and knows about gaps and session breaks. In September 2026 we documented six cases where a candidate that looked good in Python did not survive the tester. This is not a complete log of every disagreement, only the cases written up in our research notes.

The rule we follow

  • Python searches the grid, ranks variants and checks causality. It is not allowed to declare a result.
  • The MT5 tester decides, including over Python.
  • A useful side effect: whatever has passed the tester stays valid even when we later find a bug in the Python model.

Result: six cases

1. A look-ahead leak in a trend filter. The buggy version gave p = 0.002 on the tuning window and p = 0.008 on the check window, so it looked confirmed out of sample. The filter compared price with the close of the same day, which is not known yet when the trade is placed. The tester showed −906 USD gross where Python had shown a gain. After the fix: p = 0.076 and 0.180, nothing left. This filter was our attempt to rescue the rule from case 6 after it had failed. Running it on the same check window again was itself a mistake: a check window can be used only once. More on this kind of leak in a later entry.

2. One spread figure for fifteen years. A gold scalper showed +1.15 basis points per trade in Python and −1.5 bp (−1,797 USD) in the tester. Python charged one cost figure, 1.35 bp, calibrated on 2021 onwards, to data back to 2011. In 2011–2015 gold's spread at that hour was about 3.6 bp, nearly three times more. After costs were charged per trade from each entry bar's own spread plus commission, 50 of the 53 candidates from that scan disappeared; of the remaining three, one passed validation and then also failed in the tester. We described this error in detail in The constant-spread error.

3. Swap that Python did not count. A gold scalper entering at 22:00–23:00 broker server time looked good in Python. In the tester the position was still open at the midnight rollover and paid 7,471 USD in swap. A US30 candidate whose holding period also ran into the rollover paid 9,131 USD the same way. More on swap in Overnight swap bigger than the gross profit.

4. Bars missing from the broker's history. A EURJPY rule trading hour 0 showed +1.24 bp per trade in Python. The tester gave a profit factor of 0.35, but on only 109 trades against Python's 1,709, because the broker had no data for most hour-0 bars in 2011–2022. The two runs did not test the same history, so the Python result could not be confirmed; we dropped the rule.

5. A DAX scan. +0.40 bp per trade in the Python scan, −782 USD in the tester with full costs on 2023–2026. We did not isolate a single cause; the margin per trade was too thin to survive real trading conditions.

6. A rule that held only on the tuning window. A gold rule based on the five-day change in real US yields (10-year TIPS) was tuned on 2011–2020. Here Python and the tester agreed on the base version (profit factor 0.888 in Python, 0.88 in the tester). The best of 72 tuned variants (short side only) reached p = 0.016 in a permutation test; with 72 variants that is not strong evidence on its own. The check window (January 2021 to September 2026), run once in the tester, gave 367 trades, net −2,370 USD, profit factor 0.91 and Sharpe −0.76. A plausible explanation: in those years real yields rose sharply and gold still gained 92%. This case is not a Python bug; it is in the list because the tester run on fresh data was the step that stopped it.

Why it happens

  • Costs are a time series. One spread number is only valid on the window where it was measured.
  • Time stamps decide which nights you pay for. An entry an hour before rollover is an overnight trade, whatever the strategy intends.
  • Your data is not the broker's data. A missing hour in the broker's history means trades that could never have happened.
  • A leak can pass an out-of-sample test. Case 1 passed two windows with small p-values before the tester caught it.
  • A relationship can stop working. Case 6 most likely did not survive a new regime; with best-of-72 tuning, it may also never have been real.

What it means for a trader

  • Treat a Python or spreadsheet backtest as a filter that produces candidates, not as proof.
  • Before trusting any result, run the exact rules in the platform you will trade on, with the broker's own history.
  • When the two disagree, do not average them. Look for the cause; in four of the six cases it was an error in the Python model.

Limits

These are six cases from one month, five research lines (cases 1 and 6 concern the same rule). The tester is a judge only when the broker's history is complete. Where the broker has no real tick history we mark the window as diagnostic, and then only a pre-registered forward test can promote a strategy. The tester has its own bias as well: it applies today's swap points to old prices, so on multi-night trades before 2022 it charges more than our rate-based model on the side that pays swap, and credits more on the side that earns it. The amounts above are tester results at fixed test lot sizes, not account results. Past results do not guarantee future ones.

Written and reviewed by AI agents (Claude and Gemini models) under rules set by the owner; no person reviews each text. Last AI review: 3 Dec 2026. Sources are listed at the end of the article.

Questions

Is a Python backtest useless?

No. It is the fastest way to search and rank many rule variants. In our process it chooses candidates; the broker's tester decides whether they work.

What was the most common reason for the difference?

Costs. In two of the six cases Python understated the costs: one spread figure from 2021 applied to data back to 2011, and overnight swap it did not count at all (7,471 USD on gold, 9,131 USD on US30 in the tester). The DAX case may be a third; we did not isolate its cause.

Can the strategy tester itself be wrong?

Yes. It needs complete broker history, and it charges today's swap points at old prices, so on multi-night trades before 2022 it charges more than our rate-based model on the side that pays swap. Where the broker's history is incomplete, only a pre-registered forward test decides.

Sources

  1. Strategy Testing – MetaTrader 5 Help — MetaQuotes
  2. Backtesting — Wikipedia

Past results do not guarantee future results. This is research, not a recommendation to trade.

Read next