# The Degree Of Complexity

This Traders’ Tip is based on “The Degree Of Complexity” by Oscar Cagigas in the February  issue of Stocks & Commodities.
The five Donchian breakout systems described by Cagigas in his article are coded using the following rules:

The EDS code file has the backtests already set up for all of these long and short rules. In Figure 5, I show a typical setup for the pricing. In Figure 6, I show a typical setup for the exit rule.
FIGURE 5: AIQ. Here is a typical setup for the pricing portion of the backtests.

FIGURE 6: AIQ. Here is a typical setup for the exit portion of the backtests.
```!THE DEGREE OF COMPLEXITY
!Author: Oscar G. Cagigas, TASC Feb 2014
!Coded by Richard Denning 12/7/13
! CODING ABBREVIATIONS:
C is [close].
H  is [high].
L  is [low].
O is [open].
PEP  is {position entry price}.
PD     is {position days}.
! PARAMETERS:
donLen1 is 40.
donLen2 is 15.
atrLen is 20.
atrMult is 1.0.
atrStop  is 4.0.
maLen1  is 10.
maLen2  is 100.
rsiLen is 14.
rsiUpper  is 70.
rsiLower  is 30.
atrMult2 is 0.6.
minMov is 0.01.
!------------------------------------------------------------------
! AVERAGE TRUE RANGE (AS DEFINED BY WELLS WILDER)
WWE is 2*(atrLen-1).
TR  is Max(H - L,max(abs(valresult(C,1) - L),abs(valresult(C,1)- H))).
ATR is expAvg(TR,WWE).
ATR1 is valresult(ATR,1).
!------------------------------------------------------------------
!! RSI WILDER
!To convert Wilder Averaging to Exponential Averaging use this formula:
!ExponentialPeriods = 2 * WilderPeriod - 1.
U  is C-valresult(C,1).
D  is valresult(C,1)-C.
eLen is 2 * rsiLen - 1.
AvgU  is ExpAvg(iff(U>0,U,0),eLen).
AvgD  is ExpAvg(iff(D>=0,D,0),eLen).
rsi  is 100-(100/(1+(AvgU/AvgD))).
!----------------------------------------------------------------
!BASIC SYSTEM 2P (2 parameters):
HHdL1 is  highresult(H,donLen1,1).
HHdL2 is  highresult(H,donLen2,1).
LLdL1 is lowresult(L,donLen1,1).
LLdL2 is lowresult(L,donLen2,1).
Sell2P if L < LLdL1.
ExitSell2P if H > HHdL2.
Sell2Ppr is min(O,LLdL1 - minMov).
ExitSell2Ppr is max(O,HHdL2 + minMov).
!-----------------------------------------------------------------
!FOUR PARAMETER SYSTEM 4P:
Buy4P if H > HHdL1 and valrule(TR < atrMult*ATR,1).
EB4P1 if L < LLdL2.
EB4Pval is PEP - atrStop*valresult(ATR,PD).
EB4P2 if L < valresult(EB4Pval,1).
Sell4P if L < LLdL1 and valrule(TR < atrMult*ATR,1).
ES4Pval is PEP + atrStop*valresult(ATR,PD) .
ES4P1 if H > HHdL2.
ES4P2 if H > valresult(ES4Pval,1).
ExitSell4P if ES4P1 or ES4P2.
iff(EB4P2,min(O,valresult(EB4Pval - minMov,1)),-99)).
Sell4Ppr is min(O,LLdL1 - minMov).
ExitSell4Ppr is iff(ES4P1,max(O,HHdL2 + minMov),
iff(ES4P2,max(O,valresult(ES4Pval + minMov,1)),-99)).
!----------------------------------------------------------------
!SIX PARAMETER SYSTEM 6P:
SMA1 is simpleavg(C,maLen1).
SMA2 is simpleavg(C,maLen2).
Buy6P if H > HHdL1 and valrule(TR < atrMult*ATR,1)
and valrule(SMA1 > SMA2,1).
EB6P1 if L < LLdL2.
EB6Pval is PEP - atrStop*valresult(ATR,PD).
EB6P2 if L < valresult(EB6Pval,1).
Sell6P if L < LLdL1 and valrule(TR < atrMult*ATR,1)
and valrule(SMA1 < SMA2,1).
ES6Pval is PEP + atrStop*valresult(ATR,PD) .
ES6P1 if H > HHdL2.
ES6P2 if H > valresult(ES6Pval,1).
ExitSell6P if ES6P1 or ES6P2.
iff(EB6P2,min(O,valresult(EB6Pval - minMov,1)),-99)).
Sell6Ppr is min(O,LLdL1 - minMov).
ExitSell6Ppr is iff(ES6P1,max(O,HHdL2 + minMov),
iff(ES6P2,max(O,valresult(ES6Pval + minMov,1)),-99)).
!---------------------------------------------------------------
!EIGHT PARAMETER SYSTEM 8P:
Buy8P if H > HHdL1 and valrule(TR < atrMult*ATR,1)
and valrule(SMA1 > SMA2,1) and valrule(RSI >= rsiUpper,1).
EB8P1 if L < LLdL2.
EB8Pval is PEP - atrStop*valresult(ATR,PD).
EB8P2 if L < valresult(EB8Pval,1).
Sell8P if L < LLdL1 and valrule(TR < atrMult*ATR,1)
and valrule(SMA1 < SMA2,1) and valrule(RSI <= rsiLower,1).
ES8Pval is PEP + atrStop*valresult(ATR,PD) .
ES8P1 if H > HHdL2.
ES8P2 if H > valresult(ES8Pval,1).
ExitSell8P if ES8P1 or ES8P2.
iff(EB8P2,min(O,valresult(EB8Pval - minMov,1)),-99)).
Sell8Ppr is min(O,LLdL1 - minMov).
ExitSell8Ppr is iff(ES8P1,max(O,HHdL2 + minMov),
iff(ES8P2,max(O,valresult(ES8Pval + minMov,1)),-99)).
!----------------------------------------------------------------
!NINE PARAMETER SYSTEM 9P:
Buy9P if H > HHdL1 and valrule(TR < atrMult*ATR,1)
and valrule(SMA1 > SMA2,1) and valrule(RSI >= rsiUpper,1)
and valrule(TR > atrmult2*ATR,1) .
EB9P1 if L < LLdL2.
EB9Pval is PEP - atrStop*valresult(ATR,PD).
EB9P2 if L < valresult(EB9Pval,1).
Sell9P if L < LLdL1 and valrule(TR < atrMult*ATR,1)
and valrule(SMA1 < SMA2,1) and valrule(RSI <= rsiLower,1)
and valrule(TR > atrmult2*ATR,1) .
ES9Pval is PEP + atrStop*valresult(ATR,PD) .
ES9P1 if H > HHdL2.
ES9P2 if H > valresult(ES9Pval,1).
ExitSell9P if ES9P1 or ES9P2.