Audio played live by your browser, with no audio file or extra download.
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.
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.
Five parts that are written before any result is looked at, and here as they were written for this lesson’s test
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.
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.
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 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
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.
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 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 and the same years, on two official rates: two different results
On small screens, drag the diagram sideways to see all of it
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.
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 toldThe 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.
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 trap | What it does to the result | In this lesson’s test |
|---|---|---|
| Information that was not available that day | Makes a profit that was not possible | Execution at the next day’s price |
| Only what remained | Leaves out what disappeared | One pair with an unbroken record, and no generalising to any other |
| The best of many attempts | Makes chance look like a rule | 499 declared variants, and a verification period that was not seen |
| Costs that were not counted | Embellishes the result | Two pips per change; and overnight financing, whether a deduction or an addition, is absent and mentioned |
| A price that was not traded at | Gives a number that no one would have obtained exactly | Recalculation on a second official rate |
WarningLeveraged 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.