Reading the market Intermediate

Testing an idea before risking money

Lesson 14 of 14 ~11 min read

Listen to the lesson

Audio played live by your browser, with no audio file or extra download.

Preparing your device’s voice...
Ready to read the lesson aloud.

A backtest is the application of a trading rule written in advance to past prices, day by day, to find out what it would have produced had it been applied without intervention. It tells you that for the prices it was run on, with the costs that were put into it, and nothing beyond that.

This lesson runs one test in front of you, written before it was run and chosen to show the traps of testing, not to find a rule that succeeds. It then presents what came out of it as it came out.

Why is the test written before it is run?

Because anyone who sees the result first can change the rule until they like it, and then present it as if it had been their plan from the start. The method that this level used in its tests prevents that: the question, the data and the period, the method, what counts as a result in each direction, and the number of variants that will be tried are written down; then it is run, then the result is published, whatever it is.

The rule tested is one of the simplest of what is written about moving averages: a buy position in EUR/USD when the short simple moving average (SMA) is above the long one, a sell position when it is below it, and always staying in the market. Every length from 5 to 100 days was tried for the short one, in steps of 5, and from 20 to 300 days for the long one, in steps of 10, provided that the short one is shorter: 499 variants. The prices are from the H.10 release of the US Federal Reserve Board, and the days here are days that have a reference rate, not calendar days. The winner was chosen on the years 1999–2012 alone, that is, in-sample, then run unchanged on the period from 2013 up to 25 September 2026, that is, out-of-sample, a period that was not looked at when choosing.

The test as written before it was run: this lesson’s test
1. The question
Does the best two-average crossover rule hold up in a period in which it was not chosen?
2. The data and the period
The daily EUR/USD reference rate; selection in 1999–2012, and verification in 2013–2026.
3. The method
The day’s signal is executed at the next day’s price, with a cost of two pips per change, and no overnight financing (swap).
4. What counts as a result
Out-of-sample: a t-statistic above 2 means that it held up in this period, and below negative 2 that it lost, and between them there is no measurable result.
5. The number of variants tried: 499, and it is written before the run, not after it
Source: the text of the test as it was registered on 3 October 2026, before it was run, shortened.

Five parts that are written before any result is looked at, and here as they were written for this lesson’s test

The first trap: information that was not available that day

The easiest way to make a good-looking result is for the test to use something that no one knew at that moment. In this level there are examples of this: a support zone defined by a peak that is not known to be a peak until 15 prices later, and the Commitments of Traders (COT) report, which carries Tuesday’s date and is usually published only on Friday. And in the rule itself: the average calculated on today’s price cannot be traded at today’s own price, because the average is not known until after that price. That is why every signal in this test is executed at the next day’s price.

The second trap: only what remained

A test that runs only on what has remained to this day, of pairs, instruments or accounts, leaves out what disappeared along the way, and what disappeared is not a random sample. This test runs on one pair whose price has been published without a break since 1999. But choosing a pair that is still traded today is itself a choice of what remained, and its result says nothing about any other.

The third trap: the best of 499 attempts

Each variant gives a number that measures the strength of its result: the t-statistic of its mean daily return, that is, the mean divided by its standard error. The standard error measures how much the mean changes from one sample to another by chance alone, and the next level returns to it. A result whose statistic exceeds 2, upward or downward, is usually regarded as beyond what can be attributed to chance. This calculation assumes that daily returns are independent of one another, which is an optimistic assumption.

But when 499 variants are tried, about one in twenty is expected to exceed this threshold by chance, even if no rule had any real effect: 499 × 0.05 = 24.95, that is, about 25 variants. And the best of 499 variants looks good partly because it was chosen for being the best. This is overfitting: a rule that describes the past it was chosen on more than it describes anything else.

The t-statistic of 499 variants, in-sample and out-of-sample A dot for each of 499 variants of a two-moving-average crossover rule on the EUR/USD reference rate, after a hypothetical cost of two pips for each change in position and without overnight financing. The height is the t-statistic of the mean daily return. In the upper panel are the 1999–2012 results, ordered from the weakest on the left to the strongest on the right, and in the lower panel the 2013–2026 results for the same variants in the same order. The two dashed lines are at 2 above zero and 2 below it. The in-sample winning variant, 55 and 100 days, is a circle: its statistic is 2.34 in-sample and 0.34 out-of-sample. In-sample, 3 variants exceeded the two lines, and out-of-sample one variant did. The number expected by chance is about 25 on average, but it fluctuates a lot from one test to another because the variants move together, and its median value in a simulation of chance is only 3. The horizontal axis is a rank, not time, and increases from left to right. 499 variants: their ranking before 2013, and what became of them after it t-statistic after a cost of two pips per change (hypothetical example), no overnight financing From 1999 to 2012: in-sample, ordered from the weakest to the strongest negative 2 zero positive 2 The winner: 2.34 From 2013 to 2026: out-of-sample, in the same order negative 2 zero positive 2 The winner: 0.34 Each dot is a variant, and its axis is the t-statistic of the mean daily return Source: US Federal Reserve Board, H.10 release, noon rate in New York, up to 25 September 2026, which is one reference rate for each day, and not a price at which it was possible to trade. All the results are calculated from this data by a rule written before the run, and are not from the source’s publication.

The in-sample winner (the circle) at the top of the ranking, and after 2013 in the middle of the cloud

On small screens, drag the diagram sideways to see all of it

The fourth trap: costs that were not counted

A test without costs gives a result that no one would have obtained. That is why this test was run twice: once with no cost, and once with two pips for each change in position, which is a hypothetical example of a spread of two pips. As for overnight financing, it was left out of both runs, because this data does not allow it to be calculated reliably. So no result here equals what a live account would have seen: overnight financing is absent from the result, and it is a deduction or an addition for each night on which the position stays open.

The winning rule before and after cost, in-sample and out-of-sample Two lines for the value of 100 units following the winning rule, 55 and 100 days, on the EUR/USD reference rate from May 1999 to September 2026: before cost, and after a hypothetical cost of two pips for each change in position, and the two lines are almost identical. No overnight financing in either, and both on a reference rate, not a trading price. A vertical line at the start of 2013 separates the period in which the rule was chosen from the period that was not seen. Time runs from left to right. The winning rule: the value of 100 units, before and after cost Without overnight financing, and on a reference rate at which it is not possible to trade Before cost After two pips per change (hypothetical example) 100 150 200 250 300 350 The rule was chosen here and this period was not seen 2000 2005 2010 2015 2020 2025 Source: US Federal Reserve Board, H.10 release, noon rate in New York, up to 25 September 2026, which is one reference rate for each day, and not a price at which it was possible to trade. All the results are calculated from this data by a rule written before the run, and are not from the source’s publication.

Before and after cost: the two lines are almost identical because the winning rule seldom changed its position, and overnight financing is absent from both

On small screens, drag the diagram sideways to see all of it

The fifth trap: a price that was not traded at

The price the test ran on is the noon rate in New York from the H.10 release of the US Federal Reserve Board. The Board says that these rates are “certified by the Federal Reserve Bank of New York for customs purposes”. And the European Central Bank (ECB) says of its reference rate for the euro: “Using the rates for transaction purposes is strongly discouraged.” The two official rates are set at two times of day about four hours apart, and they differ by ten pips or more on 75.3% of the days since 1999. So the winning variant was recalculated on the ECB’s rate, with the same rule and in the same years.

The same rule on two official reference rates Two lines for the same winning rule, 55 and 100 days, in the same years from 1999 to 2012, each on the days on which it has a reference rate, after a hypothetical cost of two pips for each change and without overnight financing: the first on the noon rate in New York from the H.10 release, and the second on the ECB’s reference rate. The value of 100 units ends at 245 in the first and at 201 in the second, and the t-statistic is 2.34 and 1.77. Time runs from left to right. The same rule and the same years, on two official rates The value of 100 units, 1999–2012, after two pips per change (hypothetical example), no overnight financing Noon rate in New York (H.10) ECB rate 100 150 200 250 2000 2002 2004 2006 2008 2010 2012 Source: US Federal Reserve Board (H.10 release, noon rate in New York) and the European Central Bank (the euro reference rate, set at about 14:10 Central European time), and both are reference rates and not prices at which it was possible to trade. All the results are calculated from this data bya rule written before the run, and are not from the source’s publication.

The same rule and the same years, on two official rates: two different results

On small screens, drag the diagram sideways to see all of it

What did the test show?

The test was run once, as it was written. The winning variant on 1999–2012 was a short average of 55 days and a long one of 100 days.

  • In-sample, 1999–2012: a mean annual return of 6.60% after cost and 6.65% before it, and a t-statistic equal to 2.34 after cost and 2.35 before it.
  • Out-of-sample, 2013–2026: 0.70% after cost and 0.74% before it, and a t-statistic equal to 0.34 and 0.36. And this, in the wording that was registered before the run: no measurable result out-of-sample. If the rule had a real advantage of about 4% a year before overnight financing, it would have appeared above the threshold out-of-sample on only about half of the occasions, and if it were about 2.5%, on about one occasion in five.
  • All the variants: the median value of the t-statistic out-of-sample, after cost, is 0.37. And 3 variants exceeded the threshold in-sample, and one variant out-of-sample, and the number expected by chance is about 25 on average. But the variants are similar and most of them move together, so the number fluctuates a lot from one test to another: in a simulation of chance alone by the same method it was far below 25 on most occasions, its median value is 3, and it was far above it on some. So three variants and one variant are what chance usually produces.
  • On the ECB’s rate: the same winning variant in 1999–2012 gave 5.03% a year after cost, and the t-statistic is 1.77, that is, below the threshold that it exceeded on the New York rate.

The returns here are logarithmic, that is, daily returns are added together, and the annual return is the daily mean multiplied by 252. The cost changed almost nothing, because the winner seldom changed its position; but overnight financing, which is absent, is counted for every night on which the position stays open, and this rule is in the market every night.

What does the difference between 2.34 and 0.34 measure? Part of the winning variant’s in-sample result arose from the fact that it was chosen: of 499 variants, the highest is the one whose real effect, if it exists, came together with the greatest amount of chance. A period that was not seen when choosing does not carry that same chance, so the number drops. But the difference alone does not separate two causes: the chance of selection, and a market that changed between the two periods. And both mean the same thing to anyone who reads the result of a test: the in-sample number is not an estimate of what will come after it.

So this is what the test says, and no more: a rule that exceeded the threshold on the past it was chosen on, which is something that chance alone can produce when the best is chosen from 499 attempts, and that did not show a measurable result on the past it was not chosen on, and whose result itself changed when the official rate it was calculated on changed. It is one test, on a reference rate of one pair, without overnight financing, and it is not evidence that any rule will win or lose for you.

What you are not usually told

The result of a test that is presented without the number of attempts that preceded it cannot be judged: the best attempt of many looks better than any rule deserves on its own. And in this lesson, the variant whose statistic was 2.34 on the years it was chosen on became 0.34 on the years that were not seen, and nothing changed in it except the years.

What did this level accomplish, and what did it not offer?

Every real chart in this level states the source of its data, and every chart of a reference rate says that it is not a price at which it was possible to trade. The indicators in it are calculations on past prices, and they lag by their nature. Many of the common readings in it were put in front of a test that was written before it was run, and its result was published as it came out. And what it did not offer, on purpose, is a method of trading.

The five traps, and what this lesson’s test did about each of them
The trap What it does to the result In this lesson’s test
Information that was not available that dayMakes a profit that was not possibleExecution at the next day’s price
Only what remainedLeaves out what disappearedOne pair with an unbroken record, and no generalising to any other
The best of many attemptsMakes chance look like a rule499 declared variants, and a verification period that was not seen
Costs that were not countedEmbellishes the resultTwo pips per change; and overnight financing, whether a deduction or an addition, is absent and mentioned
A price that was not traded atGives a number that no one would have obtained exactlyRecalculation on a second official rate

Summary

  • A backtest describes what a rule would have produced on past prices, with the costs that were put into it, and promises nothing after that.
  • The number of attempts is part of the result: with 499 variants, about 25 striking results are expected on average by chance alone, and the number fluctuates a lot from one test to another.
  • The winning variant here did not show a measurable result outside the period it was chosen in, and its result changed when the official rate changed.
  • Today: write down one idea you have about the market in the five parts of this level: the question, the data and the period, the method, what counts as a result in each direction, and the number of variants you will try, before you look at any chart that might confirm it.
Warning

Leveraged trading in CFDs carries high risk, and you may lose the entire amount you deposited. This lesson is an educational explanation of the nature of the product, not a recommendation to trade and not investment advice.

The next level, “Risk and psychology”, starts from position size and from the expectancy of what you do.