Jul
15

Trading System Example : Jeff Cooper Expansion Breakouts

The ideas of the system Jeff Cooper Expansion Breakouts Part 1 come from chapter 5 Expansion Breakouts of Hit and Run Trading by Jeff Cooper, it includes both breakout and breakdown trades (i.e. long and short side), it will only trade one side at a time and there are no stop and reverse orders, it requires daily data series as base data series.

The system is developed in NeoTicker formula language. In the following paragraphs there are a couple of coding tricks that will be discussed in detail, along with a line by line breakdown of the code.

Note: lines start with ‘ are comments in formula language, since comments do not contribute to logic these lines are skipped in numbering and will not be mentioned in code breakdown.


1 $mysize := param1;
2 $myentry := param2;
3 $myprotective := param3;
4 $myexitbar := param4-1;

'make a month bar out of the underlying daily bars
5 compressseries(monthseries, data1, ppMonthly, 1);

'save position direction information
6 pos_dir := if(openpositionlong>0, 1, if(openpositionshort>0, -1, 0));

'long signal two calendar month high
7 $longrule1 := (h>monthseries.h(1)) and h>=monthseries.h and (monthseries.h>0) and (monthseries.h(1)>0);
'short signal two calendar month low
8 $shortrule1 := (l<monthseries .l(1)) and l<=monthseries.l and (monthseries.l>0) and (monthseries.l(1)>0);

'bigest range of in the pass 9 day
9 $rule2 := range(data1) > hhv(1,range(data1),9);

'save stop price value at long signal bar
10 $longstopprice := if($longrule1>0 and $rule2>0 and openpositionflat>0, c(2)-$myprotective, $longstopprice);

11 longlimit($longrule1>0 and $rule2>0, h+$myentry, $mysize, "long limit above today high");

12 longexitstop(openpositionlong>0, $longstopprice, $mysize, "exit long stop under yesterday close");

13 longexitatmarket(pos_dir($myexitbar)>0 and openpositionlong>0, $mysize, "exit long at market at 5th day");

14 $shortstopprice := if($shortrule1>0 and $rule2>0 and openpositionflat>0, c(2)+$myprotective, $shortstopprice);

15 shortlimit($shortrule1>0 and $rule2>0, l-$myentry, $mysize, "short limit below today low");

16 shortexitstop(openpositionshort>0, $shortstopprice, $mysize, "exit short stop above yesterday close");

17 shortexitatmarket(pos_dir($myexitbar)<0 and openpositionshort>0, $mysize, "exit short at market at 5th day");

18 plot1 := currentequity;

Lines 1-4: four assignment statements that store parameter values into four local valuables, by assigning user parameter to meaningfully named local valuables it makes rest of the code more readable.

There are 4 parameters users can adjust: 1, position size default at 100, since original text results are all based on stocks therefore the assumption is this system will mainly apply on stock, so 100 as a default position size is chosen. 2, entry point size default at 0.13 this is an approximation of 1/8. 3, protective stop point default at 1 this is set according to original text. 4, days to exit default at 5, this is the number of days to stay in a position if stop has not hit.

Line 5: use compressseries function to make a monthly data series from base daily data series. Main purpose of this compressseries call is for comparison of the two month calendar high and low required to generate signals.

Compressseries is a special NeoTicker formula function call. This call in the code makes an actual monthly data series, these virtual monthly data bars are generated from base daily data bars. The result of the compressseries call is used to compare highs and lows of calendar months, instead of writing multiple lines of code and using a combination of built-in indicators with multiple function calls, using compressseries call simplify programming task.

Line 6: this line use choose function to test for long or short direction of current bar, and store the test results in a data series call pos_di. This is necessary because position in this system goes flat at fix number of bar, by adding all previous position value of position direction series, the system will know how many bars this trade has been in position.

This programming trick that save long and short direction is only necessary when writing trading system in formula language, a more complex trade object is available in scripting language to provide a more complete picture of the system.

Line 7: use compressseries generated monthly bar to determine whether current bar has broken the two calendar months high to produce first part of a breakout signals.

Line 8: use compressseries generated monthly bar to determine whether current bar has broken the two calendar months low to produce first part of a breakdown signals.

Line 9: since the second part of trading signal is the same for breakout and breakdown signals, therefore only one rule statement is necessary this statement compare the current bar with highest high value of previous 9 day range bar to determine whether the current bar has the largest day range.

Lines 10, 14: when there is a long or short signal triggered, these two lines save two days ago close for placing stop order.

Lines 11-13, 15-17: these two groups of 3 lines are the actual long and short entry and exit order of the system. An entry at market order is issued when there is a long or short signal and no open position. An exit limit and exit stop is issued each bar after there is an open position.

Line 18: this line plots equity as output for this system.

This conclude line by line breakdown of code. See below for a screenshot of the system when running it on MSFT daily bars.

Expansion breakout chart

Click on the link below to downlaod system script into your local drive. Then use Indicator manager to install the system code.

Expansion Breakout System Code

Click on the link below to purchase the book from Amazon.com.

Buy the book

Discuss this article.

Leave a Comment

Blog Developed
By ContentRobot