Issue 7/2001 (No. 15)
AmiBroker Tips weekly newsletter.
Issue 7/2001. No 15.
14 March 2001.
Copyright (C)2001 Tomasz Janeczko.
All back issues available from:
http://www.amibroker.com/newsletter/
IN THIS ISSUE
1 Welcome
2 AFL Library: Detecting channel breakouts
1 Welcome

Welcome to the 7th issue of AmiBroker Tips newsletter in the 2001. This week I will focus on AFL code for detecting channel breakouts.

Just a reminder: if you have any comments/suggestions or article ideas, please don't hesitate to drop a line to newsletter@amibroker.com

2 AFL Library: Detecting channel breakouts

A breakout systems can be considered another form of swing trading, (which is a style of short term trading designed to capture the next immediate move). In other words, the trader is not concerned with any long term forecast or analysis, only the immediate price action. Volatility breakout systems are based on the premise that if the market moves a certain percentage from a previous price level, the odds favor some continuation of the move. This continuation might only last one day, or go just a little bit beyond the original entry price, but this is still enough of a profit to play for. A trader must be satisfied with whatever the market is willing to give.

One of the most basic ways of trading the breakout mode is by using "channel breakouts" which is simply buying the highest high of the last n days in the case of a n-period channel. The sell action is just the opposite - selling the lowest low of the last n days. To enhance the system a little bit we may introduce some threshold so actual buy/sell action is triggered a predefined percentage level above/below highest high/lowest low.

The AFL implementation is quite simple:

range = 27; /* channel length (bars) */
percthr = 0.5; /* percentage threshold */

/* find out channel borders */
channeltop = ref( hhv( high, range ), -1 );
channelbottom = ref( llv( low, range ), -1 );

buy = open > ( 1 + percthr/100) * channeltop;
sell = open < ( 1 - percthr/100) * channelbottom;

In order to check this system simply open Automatic Analysis window and copy this text into formula field. Note that you should change the backtesting settings so we will buy and sell at OPEN price as shown in the picture below.

This setting in conjuction with buy/sell rule that checks open price will simulate putting a buy stop/sell stop order (we put an buy stop order for the next day at price percthr % above channel top, and sell stop order for the next day at price percthr % below channel bottom).

The system needs tuning for every stock (range and threshold parameters) and it is suitable for trending markets. Here are example results of this system applied to AMD (American Micro Devices) for last 10 years (1990-2000), long trades only:

Performance for Amd
 
Total net profit: 224267.04   Total commissions paid: 4082.77
Return on account: 2242.67 %   Open position gain/loss 0.00
Buy-and-hold profit: 63474.29   Bars in test: 2705
Buy-and-hold % return: 634.74%   System to Buy-and-Hold index: 253.32%
 
Max. trade drawdown: -20796.83   System drawdown: -5022.99
 
Total number of trades: 9   Percent profitable: 66.7%
Number winning trades: 6   Number losing trades: 3
Profit of winners: 250546.02   Loss of losers: -22196.20
Total # of bars in winners: 1513   Total # of bars in losers: 280
Commissions paid in winners: 3075.33   Commissions paid in losers: 1007.44
 
Largest winning trade: 156349.08   Largest losing trade: -14613.76
# of bars in largest winner: 311   # bars in largest loser: 107
Commission paid in largest winner: 1258.81   Commission paid in largest loser: 302.90
 
Average winning trade: 41757.67   Average losing trade: -7398.73
Avg. # of bars in winners: 252.2   Avg. # bars in losers: 93.3
Avg. commission paid in winner: 512.55   Avg. commission paid in loser: 335.81
Max consec. winners: 1   Max consec. losers: 0
 
Ratio avg win/avg loss: 5.64   Avg. trade (win & loss): 25372.20
Profit factor: 11.29  

Trade list for Amd
Trade Entry date Exit date Net Profit Equity value
Long 27-02-1990 02-08-1990 -2277.06 7722.94
Long 17-01-1991 05-03-1992 15493.25 23216.19
Long 03-09-1992 07-06-1993 21953.63 45169.82
Long 21-07-1993 21-12-1993 -14916.67 30253.15
Long 25-01-1994 26-09-1995 12671.75 42924.90
Long 25-09-1996 01-10-1997 38933.93 81858.82
Long 24-02-1998 27-05-1998 -6009.92 75848.91
Long 04-11-1998 14-01-1999 3327.87 79176.78
Long 12-05-1999 03-08-2000 155090.27 234267.04

.... and that's all for this week - hope you enjoyed reading


AmiBroker Tips weekly newsletter. Issue 7/2001. Copyright (C)2001 Tomasz Janeczko. All back issues available from: http://www.amibroker.com/newsletter/