B 48 48 20 2 7 5
———‘The average of all tests gives a better picture of the robustness of the systems and the trendiness of the markets. Each value is «'10-year risk-
adjusted return,
—TABLE 5-5 Average Returns for Tests with 24-260 Trades
 
 
MA EXP LRS SWG - P&E NDAY
—D ~ 276 196 127 220 175 309Us 153 qd 26 13 27 28DM 192 139 285 -t 123 57SP 4 31 60 18 48 -80OEX -Il 2 -Il 18 I 16cL 196 165 153 13 —16 215sy _ 47 2 14 53 93 ~69Avg 116 86 76 43 51 59
Avg21759132478121W72.
 
By limiting the test periods to a more popular range, we see that the simple moving average is best, although the markets perform relatively
the same way.COMPARISON OF MAJORTREND SYSTEMS 107
 
age does not reduce trades as quickly as doubling the days in the N-day breakout. Thiscauses the average results of the two systems to be biased differently toward faster orslower trends. This is corrected by comparing the systems when they have the same num-ber of trades.
Aligning Test Results Graphically
Figure 5-6 shows the Eurodollar results when we attempt to align each of the six systemsby their test periods. The patterns are similar, but somewhat out of phase. This is especiallytrue for the breakout systems. By displaying performance of all systems by total trades,shown in Figure 5-7, we see a steady decline from left to right. As the number of tradesincreases, profits disappear.
We can conclude that trending systems, in general, are a robust trading vehicle forEurodollars, but only if we apply a longer time horizon. The patterns clearly show thatincreasing trades result in overall losses. This should be a very comforting conclusion forsystems traders.
Programming the Six Systems
Omega Easy Language Code
A general systems approach to programming TradeStation’s Easy Language has beentaken in this example. The strategies are written as User Functions rather than systems.This adds flexibility and allows us to use the same programs at another time. A User Func-tion is a small program or subprogram that can be referenced (called) from other pro-grams. This shared program saves you from repeating the rules and calculations for eachnew program. .
 
FIGURE 5-6 Eurodollar results by test period. The rising pattern of profits from left to rightis not clear because of the difficulty in aligning the test period, in days, with the swing size, inpercent.
 
Eurodollar: risk-adjusted returnsAll systems by test period
 
 
Risk-adjusted retums (% drawdown)
  
 
 
 
 
4 8 16 32 50 75 100 150 200Faster ... PERIOD ... Slower
—= MA —e- EXP —¥— LRS —1- SwG —O~ P&F —V— NDAYlog TREND SYSTEMS
 
 
FIGURE 5-7 Eurodollarresults by total trades. Plotting all systems by total trades (thebottom scale) shows a clear drop in performance as trading becomes more frequent.
 
Eurodoliar: risk-adjusted returnsAll systems by total trades .
 
 
Risk-adjusted returns (% drawdown)
   
100 200 300 400 500 600Fewer ... TRADES ... More
mMA @ EXP " ¥ LRS O SwG O P&aF Vv NDAY
 
The following User Functions perform the unique calculations for each of the sixstrategies, and return the value :signal = 0, no position= 1, buy or hold long position= 71, sell or hold short position
Note that the final statement of the User Function sets the User Function name equal to thevalue of the signal. Each program also references a variable type, which indicates that themarket being processed is, or is not, an interest rate.
type = 0, default= 1, 3-month interest rate (e.g., Eurodollars, Matif Pibor, Short sterling)= 2, long-term interest rate (e.g., U.S. T-bonds, T-notes, U.K. Gilt, German bund)
SystemA system has buy and sell orders, equity calculations, and other statistics. Parameter valuescan be set from the appropriate menu. Our systems will reference a User Function to findthe signal for each strategy. Because each of the systems would be identical, except for theone line that calls the user function, only one systef is-shown.
IndicatorAn indicator is a program that displays the value of key points or calculations on a chart.An indicator can position the high and iow points of a swing (Kswing) or show a separategraph on a split page (KLRS).
{KMA : Moving Average User Function -Copyright 1994-1998, P J Kaufman. All rights reserved. }COMPARISON OF MAJOR TREND SYSTEMS 109
 
{period = length of moving average trend
filter = whole % trend change to give signal
lag = 0 to enter on close, n to enter n-days later
)
input: period(numericsimple), filter(numeric), lag(numericsimple)vars: ma(0), change(0), signal(0);
signal = signal(1];
{moving average for testing anticipation)
ma = @Average(close,period);
change = (ma - maC1})*100/close(1];
{Yong signal}
if lag >= 0 and changeLlag]>filter then signal=l;{short signal}
if lag >= 0 and changeltag]<-filter then signal= -1;KMA = signal;
{KEXP exponential User FunctionCopyright 1994-1998, P J Kaufman. Al? rights reserved.}
 
{period = length of exponential trend
filter = whole percent trend change to give signal
lag = 0 to enter on close, n to enter n-days tater
)input: period(numericsimple), filter(numeric), lag(numericsimpie);vars: exp(0), change(0), signal(0);
signal = signal(1];
{Exponential smoothing for testing anticipation}
Exp = @SmoothedAverage(close,period);
change = (Exp - Exp{1]}*100/ctose[1];
{long signal}
if Tag >- 0 and change[lag}>filter then-signal=l;{short signal)
if tag >= 0 and change[lag]<-filter then signal= -1;KEXP = signal;
{KLRS : Linear Regression Slope User Function
Copyright 1994-1998, P J Kaufman. Ail rights reserved.
Method of least squares to calculate slope}
Inputs: period(numericsimple);
vars: sumx(0), sumx2(0), sumy(O), sumxy(0), n(O), k(O), top(0), bot(o)slope(0), yint(0);
 
{Time = x, the independent variable, e.g., 1, 2, 3,...Close = y, the dependent variable}
{standard sum of integer series}sumx = period*(period+1) / 2; ~sumx2 = period*(period+l)*(2*periodt+l) / 6; .sumy = @summation(close,period);sumxy = 0;n = period;for k = 0 to period-1 beginsumxy = sumxy + n*close(k];n=n- 1;end;top = period*sumxy - sumx*sumy;bot = period*sumx2 - sumx*sumx;if bot<>0 then slope = top / bot;{yint = (sumy ~ slope*sumx) / period;} -KLRS = slope;Ho TREND SYSTEMS—__—_——
{KLRSignal : Linear Regression Slope signal User FunctionCopyright 1994-1998, P J Kaufman. All rights reserved.}
{period = length of exponential trendfilter = whole % trend change to give signal
}input: period(numericsimple), filter(numeric), lag(numeric);
vars: slope(0), signal(0);
{Call linear regression slope User Function)
slope = KLRS(close,period);
signal = signal(1];
{long signal : slope is up by more than filter}
if lag >= 0 and slope[lag]>filter then signal = 1;{short signal : slope is down by more than filter}if lag >= 0 and slope[Llag]<-filter then signal = -1;KLRSignal = signal;
 
(KNOB : N-Day Breakout User FunctionCopyright 1994-1998, P J Kaufman. All rights reserved.}
{INPUT for N-day Breakout System signal rules:BUY when high is above N-day high and close > prior closeSELL when low is below N-day low and close < prior close}
input: pertod(numeric); .vars: nhigh(0), nlow(0), signal(0);
nhigh.= highest (highL1],period - 1);
nlow = lowest(low{1],period - 1);
{Buy and sell signals}
signal = ‘signal(1];
if high > nhigh and close > close[1] then signal ~ 1if low < nlow and close < close[1] then signal - -KNOB = signal;
 
{KSWG : User Function to determine swing direction and new swing highs or lowsCopyright 1994-1998, P J Kaufman. All rights reserved. }
(INPUT for KSWG -swing in whole percentdirection & breakout:+1 up, +2 up breakout0 none-1 dn, -2 dnbreakouttype : 0= normal, 1= 3 month rate, 2= bondsignal rules:buy when upswing jis above prior upswingsell when downswing is below prior downswing}input: swing(numeric), type(numericsimple);vars: minswing(0), last(0) , curhigh(0) , curlow(0), swhigh(0), swlow(0),swingdir(0), signal(0);
minswing = swing*close/100;if type=1 then minswing = swing*(100 - close) / “1005if type=2 then minswing = swing*(B./close)
(SWINGS: Initialize most recent high and low}
if (currentbar = 1)then begin
curhigh = close; {current high)curlow = close; {current low}end; - -
(Search for a new high}if last<>1 then beginCOMPARISON OF MAJORTREND SYSTEMS. mw
if high > curhigh then curhigh = high; {new current high}if low < curhigh - minswing then beginlast = 1; {last high fixed}swhigh = curhigh; {new verified high}curlow = low; {initialize new lows}end;end{Search for a new low}else begin
if last <> -1 then beginif low < curlow then curlow = low;if high > curlow + minswing then beginlast = -1;swlow = curlow;curhigh = high; {initialize current high}end;end;end;{Buy and sell signals}signal = signal[1];swingdir = 0;if last = 1 then beginswingdir = -1;if curlow < swlow then signal =end; .if last = -1 then:beginswingdir = 1;if curhigh > swhigh then signal = 1;end;KSWG = signal;
 
 
{KPF > Point & Figure User Function *Copyright 1994-1998, P J Kaufman. All rights reserved.)(INPUT for KMA_PF_System, swing in whole percentdirection & breakout:
+1 up, +2 up breakout
0 none
-1 dn, -2 dnbreakouttype : 0= normal, i= 3 month rate, 2= bondsignal rules:
buy when upswing is above prior upswing
sell when downswing is below prior
downswing}
input: box(numeric), revboxes (numeric);vars: minswing(0), last(0), curhigh(0), curlow(0), swhightG), swlow(0),swingdir(0), Signal(0);
{For percentage calculations:
minswing = swing*close/100; ~
if type=l then minswing = swing*(100-close) / 100;if type=2 then minswing = swing*(8./close)}minswing = box*revboxes;
(SWINGS: Initialize most recent high and low}
if currentbar = 1 then begin
curhigh = close; {current high}curlow = close; {current low}end; ~
{Search for a new high}if last©> 1 then begin 7if high > curhightboxsize then curhigh = high; {new current high}112 . TREND SYSTEMS
 
if low < curhigh - minswing then begin
last = 1; {last high fixed}swhigh = curhigh; {new verified high)curlow = low; {initialize new lows}end;end{Search for a new low)else begin
if last <> -1 then beginif low < curlow-boxsize then curlow=low;if high > curlowtminswing then beginlast = -1;swlow = curlow;curhigh = high, (initialize current high}end;end;end;{Buy and sell signals}signal = signal[1];swingdir = 0;if last = 1 then beginswingdir = -1;if curlow < .swlow then signal = -1;end;if last = -1 then beginswingdir = 1;if curhigh > swhigh then signal = 1;end;KPF = signal;
SYSTEM -
The following system can be used for any of the six methods by changing the braces (com-ment notation)
{System Signals.Copyright 1994-1998, P J Kaufman, All rights reserved.|}
{type ~ 0, default, ‘1, 3-month rate2, long-term ratesperiod = length of calculation :swing = swing filter in whole percent (i.e., 1.5 = l'/ percent)filter = whole % trend change to give signal4input: type(0), period(0), swing(0), box(0), revboxes(0), filter(0), 1ag(0);vars: signal(0); .
{Call User Function}signal = KMA(period, filter,lag);{signal = KLRSignal(period);){signal = KNDB(period);} oe{signal = KSWG(type); }{signal = KPF(box, revboxes);}if signal = 1 then buy at close;if signal = -1 then sell at close;
INDICATOR
The KMA Swing Indicator plots the high and low swing points above and below the corre-sponding prices. Select the scale-by-price feature.COMPARISON OF MAJOR TREND SYSTEMS 13
 
{KMA SWING: Finds most recent swinghighs and jows.Copyright 1994-1998, P J Kaufman. All rights reserved. .
Inputs for KMA SWING:swing = price swing in %type = 0, normal; 1, 3-month rate; 2, bond rateindex = 0, treat as price;1, create index series} ‘input: swing(1.5), type(0), index(1);vars: pcswing(0), last(0), curhigh(0), curtow(0),swhigh(0), swlow(0), highbar(0), lowbar(0),chighbar(0), clowbar(0), lowp(0), highp(0),aclose(0), ahigh(0), alow(0), xclose(0),xhigh(0), xlow(0), factor(1);
peswing = swing/100.;aclose = close;ahigh = high;alow = low;factor = 1;if type <> 0 then factor = -1; '{Adjust prices if interest rates}if type = 1 then begin*aclose = 100. - close;ahigh = 100. - low;alow = 100. - high;end;if type = 2 then begin;aclose = 800./close;ahigh = 800./close;alow = 800./close;end;{Initialize most recent high and low}if currentbar = 1 then beginif index = 0 then begin -xclose = aclose;xhigh = ahigh; -xlow = alow;endelse beginxclose = 100.;—_xhigh = ahigh*100 / aclose;x1l0w = alow*100 / aclose; -
end;curhigh = xclose; — {current high}curlow = xclose; - {current low}end _else begin _
if index = 0 then beginxclose = aclose; - -xhigh = ahigh;xlow = alow;endelse beginxclose = xclose[1] + (aclose ~ aclose{1])*100 / aclose[1];xhigh = xclose{l] + (ahigh - aclose(1])*100 / aclose[1]; -xlow = xclose[1] + (alow - aclose{1])*100 / aclose(1];end:4 TREND SYSTEMS
eee
end;{Search for a new high - favor reversals}if last<>1 then begin{Reverse from high if minimum % swing}if xlow < curhigh - curhigh*pcswing then beginlast = 1; {last high fixed}swhigh = curhigh; {new verified high}highbar = chighbar;curlow = xlow; (initialize new lows}lowp = low;clowbar = currentbar;ploti[currentbar - highbar}(high[currentbar - highbar}+ factor*hi ghp*pcswing/4, "swinghigh");
endelse beginif xhigh > curhigh then begincurhigh = xhigh; {new current high}chighbar = currentbar;end;end;
end;(Search for a new low - favor reversal}if last <> -1 then begin .{Reversal from:low if minimum % swing}if xhigh > curlow + curlow*pcswing then begin.last = -1;- 5swlow = curlow;lowbar = clowbar;curhigh = xhigh; {initialize current high}highp = high;chighbar = currentbar;plot2[currentbar - Jowbar} (1 owLcurrentbar - lowbar]-factor*lowp*pcswing/4, “swinglow");endelse begin \.if xlow < curlow then begincurlow = xl0w;clowbar = currentbar;
XNend;end;end;
Spreadsheet CodeIn the following QUATTRO code, the .“$” GENERAL DESCRIPTIONprecedes a row or column that is fixed A6é Date (YYMMDD)(i.e., it does not get copied down). B6 High price oo
~ C6 Low price
Moving average, exponential, and N-day 06 Closing price
breakout share the same page, as do the C3 Test period, swing %, or box size
swing breakout and point-and-figure system. C5 Point-and-figure number of reversalboxes
The price data is not repeated to save space. All data starts in row 7MOVING AVERAGE
C3 period (e.g., 5 day)E3 filter (e.g.,.10 for OEX data)COMPARISON OF MAJORTREND SYSTEMS His
 
Repeated process (copy down)
Ell MA @Avg(07..011)
Fll Dir @IFCE1] - E10>$E$3,1,@IF(E11 - £10<-$€$3,-1,F10))
Gll Entry @IF(F11=_1#AND#F10<>-1,"Se11",@IF(F11=14AND#F10<>1, "Buy", *"))
EXPONENTIAL SMOOTHING
C3 period (e.g., 5 day)
E3 filter (e.g.,.10 for OEX data)
G3 smoothing constant 1 / (C3+1)
Initialize
£6 EXP +06 ‘
Repeated process (copy down)
E7 EXP +E6+$G$3*(D7 - £6)
FT Dir @LF(E7 - E6>$E$3,1,@1F(E7 - E6<-$€$3,-1,F6)
G7 Entry @LF(F7=-1#AND#F6<>-1, "Se11” ,@IF(F7=1ANDHF6<>-1, "Buy", ""))
N-DAY BREAKOUT
Repeated process (copy down). There are no constants and no initializationEll Nhigh @Max(B6..B10)
Fll Niow  @Min(C6,.C10)
G11 Dir @LF(B11>E1 1#AND#D11>010,1,@1F(C11<F114AND#D11<010,-1,G10))Hil Entry @LF(G11=-1/#AND#G10<>-1, "Se11”,@IF(G11=1#AND#G10<>1, "Buy",""))
SWING BREAKOUT
C3 Minimum swing percentage -E6 CurH +86
Fe CurL +C6
G6 H/L @IF(D6>(E6+F6)/2,-1,1})
E7 CurH @IF($G6--1#AND#B7>E6,B7 ,@IF($G6~1,B7,£6))F7 Curl @IF($G6=1#AND#C7<F6,C7 ,@1F($G6=-1,C7,F6))G7 H/L @IF($G6~-1, @IF(C7<E7 - $C$3*D7,1,$G6),@IF(B7>F7+$C$3*D7,-1,$66))H7 SwH  @IF($G7=1#AND#G6=-1 ,E7 ,H6)17 SwL  -@LF($G7--1/AND#G6=1,F7, 16)U7 Entry @1F($G7—- 1AND#B/>H7#AND#D7 >06 , "Buy",
@IF ( $67=1#ANDHC7 <i 7#AND#D7<D6, "SETI", ""))
NOTE: The point-and-figure spreadsheet code varies slightly from the TradeStation code.It is a more accurate representation of the exact point-and-figure charting method (favor-ing reversals when possible).
POINT AND FIGURE
C3 Point and figure box sizecs Number of reversal boxesE6 CurH @INT(B6/$C$3)
Fé CurL @INT((C6+$C$3)/$C$3)
G6 Dir @IF(D6>(E6+F6)/2,1,-1)
E7 CurH @IF($G6=1 ,@1F(@INT(b7/$C$3)>E6 ,@INT(B7/$C$3),E6) @INT(B7/$C$3))
F7 CurL .@IF($G6=-1,@IF(@INT((C7+$C$3)/$C$3)<F6,@INT( (C7+$C$3)/$C$3)),F6 ,@INL( (C7+$C$3)/$C$3))
G7 Dir @IF(G6=- L#HANDH@INT(B7/$C$3)>F74+$D$3-1),1,@1F (G6=1#AND#@INT((C7+$C$3)/$C$3)<E7 - ($D$3-1),-1,G6))
H7 LastH @LF(G7=-1#AND#G6=1,,E7 ,H6)
17 LastL @IF(G7=1#AND#G6=-1,F7,16)
07 Entry @IF(G7=-1#ANDH@INT((C7 - $C$3)/$C$3)<17,"Sel1",@IF(G7=14ANDI@INT(B7/$C$3)>H7, “Buy”, ""))
LINEAR REGRESSION SLOPE
c3 périod (e.g.,5) _E3 filter (e.g. ,0)
Initialize .116 TREND SYSTEMS
 
E6 Timex 1 .
G6 X42 E6*E6 (copy down} tJ6 xy E6*D6 (copy down)
Normal processing (copy down all cells)
E7 TimeX +E6+1
F10 SumX  @Sum(E6..£10)
G10 XA2 +E10*E10
H10 SumX*2 @Sum(G6. .G10)
110 Sumy  @Sum(D6..D10)
J10 XY +E10*010
K10 Sumxy @Sum(J6, .J10)
L10 Slope ($C$3*K10 - F1lO*I10) / ($C$3*H10 - F10*F10)
M10 Dir @IF(LIO>SESSH#ANDHLOCSES3, 1, @IF(LIO<-SES3#ANDHL9> - $E$3, ~ 1,M10})N10 Entry @IF(M10=-1#AND#M9<>-1,"Se11",@IF(M10=1#AND#M9<>1, "Buy", ""))
To verify that the correct code was entered into the spreadsheet, Figure 5-8 shows a sam-ple of the opening lines of the spreadsheet using sample data. The columns E, F, G, and Hhave been repeated for each of the moving average, exponential smoothing, and N-daybreakout systems. In Figure 5-9, this approach has been taken for the swing breakout andpoint-and-figure systems using the same data. ©
TECHNIQUES USING TWOTRENDLINES +
This section is restricted to applications of trendlines; however, do not assume that trend-lines constitute the only timing methods. Any secondary system that analyzes a shortertime period than the primary system can be considered as a timing device. Typically, a3-day moving average could act as a timing technique for a 10-day average; however, thedelays of 1, 2, 3, or more days, discussed earlier, are also for timing. A 5-day delay wouldnot be a sensible choice to be used with a 3-day moving average, because the two periodswould be incompatible. Plotting of lag and lead moving average values is another possibletiming method. In this section, the use of more than one moving average will be examined(any type of trend approach would apply) to create a system.
In using two averages, the slower one, requiring a longer calculation period, willdetermine the long-term trend. The faster average will be used for timing. The long-termmoving average generates a signal compatible with the long-term trend, regardless ofrecent patterns. A trader would be more comfortable knowing that there is a recent short-term surge of prices in the direction of the new position at the moment of entry. To imple-ment this idea, select two moving averages, one noticeably faster than the other, and applyeither of the two following rules:
1. Buy when the faster moving average crosses the slower moving average going up.~~ Sell when the faster moving average crosses the slower moving average going down.
2. Buy when the current price crosses above both moving averages, and close out longpositions when prices cross below either moving average. Sel? when the currentprice crosses below both moving averages, and close out short positions whenprices cross above either moving average igure 5-10). -
The first set of rules results in constant trading, going from long to short and backagain as the long-term trend is violated by the faster trend. The second set of rules allowsfor a neutral position when the current position is closed out and the long-term trend isnot penetrated. One problem with this second approach is that the faster moving averagemay cause whipsaws by being too close to the current price. This can be solved in the sameway as the single moving average by placing a band around oné or both of the trendlines.There are other variations of these rules that can be listed, but they are not materially dif-ferent from these two.re
 
 
 
1 +V66E = 2OOIF | 000 | LVZOh GEOR «ELLOF «6960F SOz0EE IE
1 IS86E —_ZF'8OF | %6'%0r | O9'S0F G6E60F %0'8OF ZOOIh HOZ0ES OF
1 OLL6E —bB'FOF 1 €9"10r | O8€0F  %O'BOF GIO ZhBOP EOZ0ES 67
1 OLL6E = FB FOF 1 £00 1 807%OF 6IrhOF OL%OF PB FOr ZOZOEE Bz
! SL96E — E6'EOF 1 65°66 | LYIO = BOP «LE 1OF «= PB'POR 10206 LZ
1 fES6E — CEEOF 1 es86e | €900F LS10F ~FI'66E 1610 6Z10€6 9%
I LOVE E6'EOF | €626€ 1 '9966E OF OOF IS°86E 6900 8Z10E6 SZ
I L9%E - €6°E0F | er L6E | 8986E = IFGGE OLLEE ET IOP = LZ10E6 FZ
1 L9T%6E = 66'00F 1 poles 1 1926 FI IOh «6 OOF «EGEOR «9ZIDES EZ
1 LITE HY BEE 1 @96E Ang 1 L£S96E 1900F SL96E 6600F SZIOES 27
I L9%E —«EE'00F Ang 1 reS6e I- S8S6€ SL9GE EESEE 1186€ 7@ZIOE6 IZ
I 9EE6E —-ELOOF I> So'see es I- LOS6E ISS6E LEZEE LES6E I1Z10€6 0%
I ZL06E —-EL00F Iles IF 96'r6E | Z196E = OEE IOKEE «= ETLEE OOZES 61
! StB8E E00 1 prsee | QO96E %6S6E SBFEE HFBEE G6II0E6 81
1 Svese  £€'00F | 66'r6E | SI'S6€ = SI'Z6E OI'96E = LFLEE —BIIOEG LI
Ang 1 OflBE = EEIEE | SS°r6E i S6E6E LILEE SL'S6E EEOOF SII0E6 91
I-  Of2Z8€ = 89'96E Ang I €0r6e Ang | OS%6E ST9BE JEECE EE96E FIIOES SI
I- Of Z8E = 8996E I~ 9se6e I- IS16€ Ose6e ZLO6E IN PEE E110€6 +I
I