Fri05242013

Last update12:00:00 AM

Back

The TradersStudio code based on Sylvain Vervoort’s article in this issue, “Long-Term Trading Using Exchange Traded Funds,” is provided at the following websites:

• Indicator Plot: “HACOLT_IND” for displaying the weekly HACOLT indicator
• Function: “HAC” for computing the heikin-ashi close
• Function: “HAO” for computing the heikin-ashi open
• Function: “zLagHA” for computing the zero-lag TEMA of the heikin-ashi close
• Function: “zLagTP” for computing the zero-lag TEMA of the close
• Function: “HACOLT” for computing the Sylvain Vervoort’s HACOLT value
• System: “HACOLT_SYS” for backtesting Sylvain Vervoort’s system.

The code is also shown here:

'Author: Sylvain Vervoort, TASC July 2012
'Coded by: Richard Denning 5/08/2012
'---------------------------------------------------
'HEIKIN-ASHI CLOSE (as modified by author):
Function haC() As BarArray
Dim haOp As BarArray
Dim haH As BarArray
Dim haL As BarArray
Dim haCTP As BarArray
haCTP =  (O+H+L+C)/4
haOp = (haCTP[1] + haOp[1]) / 2
haH = Max(H,Max(haOp,haCTP))
haL = Min(L,Min(haOp,haCTP))
haC = (haCTP + haOp + haH + haL) / 4
End Function
'---------------------------------------------------
'HEIKIN-ASHI OPEN (as modified by author):
Function haO() As BarArray
Dim haCTP As BarArray
haCTP =  (O+H+L+C)/4
haO = (haCTP[1] + haO[1]) / 2
End Function
'---------------------------------------------------
'HA ZERO LAG TEMA
Function zLagHA(xmaLen) As BarArray
Dim haCL As BarArray
Dim haTMA1, haTMA2, haTMA3, haTMA4, haTMA5
Dim haTMA6, haTEMA1, haTEMA2, diff
haCL=haC()
haTMA1 = XAverage(haCL,xmaLen)
haTMA2 = XAverage(haTMA1,xmaLen)
haTMA3 = XAverage(haTMA2,xmaLen)
haTEMA1 = 3*haTMA1-3*haTMA2+haTMA3
haTMA4 = XAverage(haTEMA1,xmaLen)
haTMA5 = XAverage(haTMA4,xmaLen)
haTMA6 = XAverage(haTMA5,xmaLen)
haTEMA2 = 3*haTMA4-3*haTMA5+haTMA6
diff = haTEMA1 - haTEMA2
zLagHA = haTEMA1 + diff
End Function
'----------------------------------------------------
'TP ZERO LAG TEMA
Function zLagTP(price As BarArray,xmaLen) As BarArray
Dim tp As BarArray
Dim tma1, tma2, tma3, tpTEMA1
Dim tma4, tma5, tma6, tpTEMA2, diff
tp = price
tma1 = XAverage(tp,xmaLen)
tma2 = XAverage(tma1,xmaLen)
tma3 = XAverage(tma2,xmaLen)
tpTEMA1 = 3*tma1-3*tma2+tma3
tma4 = XAverage(tpTEMA1,xmaLen)
tma5 = XAverage(tma4,xmaLen)
tma6 = XAverage(tma5,xmaLen)
tpTEMA2 = 3*tma4-3*tma5+tma6
diff = tpTEMA1 - tpTEMA2
zLagTP = tpTEMA1 + diff
End Function
'-----------------------------------------------------
'Author: Sylvain Vervoort, TASC July 2012
'Coded by: Richard Denning 5/08/2012
Function HACOLT(emaLen1, candleSize, emaLen2) As BarArray
'default: emaLen1=55, candleSize=1.1, emaLen2=60)
Dim haCL As BarArray
Dim haOp As BarArray
Dim ZLHa As BarArray
Dim ZLCl As BarArray
Dim keep1 As BarArray
Dim keep2 As BarArray
Dim keep3 As BarArray
Dim keep4 As BarArray
Dim keep5 As BarArray
Dim keep6 As BarArray
Dim keeping As BarArray
Dim keeping2 As BarArray
Dim keepAll As BarArray
Dim keepAll2 As BarArray
Dim dtr As BarArray
Dim utr As BarArray
Dim upw As BarArray
Dim dnw As BarArray
Dim Result As BarArray
Dim LTResult As BarArray
Dim LTSell As BarArray
haCL = haC()
haOp = haO()
ZLHa = zLagHA(emaLen1)
ZLCl = zLagTP((H+L)/2,emaLen1)
keep1 = IIF(haCL>=haOp Or haCL[1]>=haOp[1] Or C>=haCL,1,IIF(H>H[1] Or L>L[1],1,0))
keep2 = IIF((ZLCl-ZLHa) >= 0,1,0)
keep3 = IIF(Abs(C-O)<(H-L)*candleSize And H>=L[1],1,0)
keeping = IIF(keep1=1 Or keep2=1,1,0)
keepAll = IIF(keeping=1 Or (keeping[1]=1 And (C>=O Or keep3)),1,0)
utr = IIF(keepAll=1 Or (keepAll[1]=1 And keep3=1),1,0)
keep4 = IIF(haCL<haOp Or haCL[1]<haOp[1],1,0)
keep5 = IIF((ZLCl-ZLHa)<0,1,0)
keep6 = IIF(Abs(C-O)<(H-L)*candleSize And L<=H[1],1,0)
keeping2 = IIF(keep4=1 Or keep5=1,1,0)
keepAll2 = IIF(keeping2=1 Or (keeping2[1]=1 And (C<O Or C<C[1])),1,0)
dtr = IIF(keepAll2=1 Or (keepAll2[1]=1 And keep6),1,0)
upw = IIF(dtr=0 And dtr[1]=1 And utr=1,1,0)
dnw = IIF(utr=0 And utr[1]=1 And dtr=1,1,0)
Result = IIF(upw=1,1,IIF(dnw=1,0,Result[1]))
LTSell = IIF(C<XAverage(C,emaLen2),1,0)
LTResult = IIF(Result=1,1,IIF(Result=0 And LTSell=1,0,LTResult[1]))
HACOLT = IIF(Result=1,100,IIF(Result=0 And LTResult=1,50,IIF(Result=0 And LTResult=0,0,HACOLT[1])))
End Function
'-----------------------------------------------------
Sub HACOLT_SYS(emaLen1, candleSize, emaLen2)
'defaults: emaLen1=55,candleSize=1.1,emaLen2=60
Dim theHACOLT As BarArray
theHACOLT = HACOLT(emaLen1, candleSize, emaLen2)
If Date > MigrateDate(1020701) Then
If theHACOLT = 100 Then Buy("LE",1,0,Market,Day)
If theHACOLT = 50 Or theHACOLT = 0 Then ExitLong("LX","",1,0,Market,Day)
If theHACOLT = 0 Then Sell("SE",1,0,Market,Day)
If theHACOLT = 100 Then ExitShort("SX","",1,0,Market,Day)
End If
End Sub
'------------------------------------------------------

Although Vervoort designed this system to trade ETFs, I wanted to test it on other markets since there is such limited data for ETFs and the author’s tests would all be considered “in-sample” tests. I ran a test using a portfolio of futures contracts that included the following markets from the Pinnacle Data service (reverse adjusted):

AN,BN,CN,FN,JN,SN,EC,CL,HO,NG,RB,TA,TD,UA,CC,CT,JO,KC,LB,SB,BO,C,NR,O,S,SM,W,MD,ND,SP,FC,LC,LH,GC,HG,PA,PL, and SI.

In Figure 7, I show the resulting log equity curve trading this portfolio starting with one million dollars and using a percentage-of-margin trading plan set at 20% with a 100-contract maximum. In addition, within this figure, I show the underwater equity curve. For each round-turn trade, I deducted commission and slippage of \$75 per contact. Although the test started in 1/2/1997, I prevented the trading from starting until 1/2/2000 to allow for the exponential averages to stabilize. For the period 1/2/2000 to 5/9/2012, the system returned \$3,604,893 with a maximum drawdown of 38.7% on 10/28/2011.

FIGURE 7: TRADERSSTUDIO, HACOLT SYSTEM. Here is a log equity curve with an underwater equity curve for the system on 38 different futures markets.

—Richard Denning