Back-testing
A back-test runs fixed rules over past prices and adds up the trades. Done carefully it is a cheap way to reject a method. Done carelessly it flatters almost any rule.
- Level 11 Your Trading Plan
- Lección 13 de 25
- 5 min de lectura
- 2 preguntas
Back-testing means applying a system’s rules to past prices, one candle at a time, and recording every trade they would have taken. Level 5 set out what a back-test can and cannot show. This lesson covers how to run one, using the example system from section 11.3. The system is an illustration, with no edge claimed, and the prices were made with no pattern in them.
By hand and by software
By hand, you scroll a chart back, reveal one candle at a time and apply the rules as the last lesson did, writing each trade down. It is slow, and it teaches what the rules feel like. By software, a platform’s tester does the same work in seconds. The tester’s assumptions then decide the result: when it enters, how it fills a stop, what costs it charges.
What the example test showed
Six years of four-hour candles gave 423 trades. Of these, 149 won: a win rate of 35.2%.
| Before costs | After costs | |
|---|---|---|
| Total | +20.2R | −6.5R |
| Average per trade | +0.048R | −0.015R |
The example costs are a spread of 0.8 pips, commission worth 0.6 pips, slippage of 0.3 pips and a swap of 0.3 pips a night. On an average stop of 41 pips they come to 0.063R a trade. A small profit became a small loss.
Five ways to flatter a test
Each row changes one thing in the same test.
| What was done | Result shown |
|---|---|
| Honest test, with costs | −6.5R |
| Costs left out | +20.2R |
| Orders reached through a gap filled at their own price, no costs | +24.0R |
| Test stopped at its best point, after trade 165 | +28.5R |
| Entry at the open of the signal candle, no costs | +313.4R |
The last row uses information from the future: the candle’s close is not known at its open. The third row gives fills that could not have happened. Level 1 showed that a stop is filled at the first price after a gap. Four stops in the test met weekend gaps, and one lost 2.6R where 1R was planned.
What testers assume
Read your tester’s help before trusting it. TradingView’s documentation says its strategies fill orders from chart data alone by default, apply no commission unless one is set, and typically give unrealistic results on Heikin Ashi and other non-standard charts, which is the point Level 8 made. PipCircle’s Strategy Builder has fields for commission, spread and slippage that start at zero, and it fills a stop hit through a gap exactly at the stop price, which its own notes call optimistic. Set the costs, and read its results with that in mind.
Key points
- A back-test applies fixed rules to past prices candle by candle and records every trade.
- The example system made +20.2R before costs and −6.5R after them over 423 trades in six years.
- Leaving out costs, filling gapped orders at their own price, stopping at the best point and using future information all flatter a test.
- A tester’s assumptions about entries, fills and costs decide its result. Read them first.
Comprobación rápida
Estas preguntas no cuentan para tu puntuación del cuestionario.
Common mistakes
- Testing with no costs. The example system’s profit before costs became a loss after them. A short-term rule is hit harder still.
- Letting the test see the future. Entering on the candle that gives the signal, or using a day’s high before the day has ended, produces results no trader could have had.
- Trusting fills at the stop price. A stop is filled at the first price available after a gap, and that price can be far away.
- Ending the test where it looks best. The test period is chosen before the test and not shortened afterwards.
Another example
One of the example test’s gapped trades. The system bought at 1.0983 on a Wednesday with a stop 43 pips away at 1.0940. Price was still above the stop on Friday’s close. On Monday the market opened at 1.0883, below the stop, and the stop was filled there: 100 pips lost, which is 2.33R. At 0.11 lots the loss was 110 dollars where 47.30 had been planned. A tester that fills the stop at 1.0940 records a loss of 1R and makes this trade 1.33R better than it could have been.
Questions people ask
What is back-testing in trading?
Back-testing is running a fixed set of trading rules over past prices and recording every trade they would have taken. The results show how the rules behaved in that period, with a win rate, an expectancy and a drawdown. They describe the past and do not promise the same in the future.
How do I back-test a strategy by hand?
Scroll the chart back so that later candles are hidden, then move forward one candle at a time. At each closed candle apply the rules exactly, and write down every entry, stop, target and result, including costs. Keep going for at least a hundred trades, and do not skip the losing ones.
How many years of data do I need for a back-test?
Enough to produce several hundred trades and to include rising, falling and sideways markets. For a system that trades five times a month that means several years. For a scalping rule a few months of detailed price data may hold thousands of trades, though a short period covers fewer kinds of market.
What is look-ahead bias?
It is the error of letting a test use information that was not available at the moment of the trade, such as a candle’s close when entering at its open. Results improve dramatically and are impossible to achieve. In the lesson’s example this one error turned a small profit into more than 300R.
Las lecciones se pueden leer gratis sin cuenta. Inicia sesión y PipCircle recuerda dónde lo dejaste, guarda tus puntuaciones y te otorga tus insignias. Iniciar sesión gratis
Trading foreign exchange and CFDs carries a high risk of losing money. PipCircle Learn is education and is not investment advice.