Backtesting Tutorial

 
Many successful traders backtest their strategies before they use them. A good backtest result is no guarantee of a successful trading strategy, but backtesting helps to understand what is necessary for successful trading and what mistakes you can avoid.
 
To understand how backtestig works, let´s create a very simple script.
 
The backtester uses the array variables buy and sell. The assigned expression to buy and sell is executed for each bar in a stock and returns an array with true / false values.
 
This script buys when close is below 10 and sell when the price rises above 15.
 

BUY = CLOSE < 10;
SELL = CLOSE > 15;

 

The following table contains 'close' data of a stock. Once the script is executed on the stock, the variable "buy" and "sell" are initialized with the data in the table. The stock will be purchased on bar 3 for $9 and sells for $16 on bar 7.

 

Bar

1

2

3

4

5

6

7

8

9

10

Close

12

10.5

9

9.5

12

14

16

18

15

16

Buy

False

False

True

True

False

False

False

False

False

False

Sell

False

False

False

False

False

False

True

True

False

True

 

 

 


 

 

© Copyright Erich Behmen 2009 - 2011. All Rights Reserved