SLV”,C);SEC3:=Security(“C:\Metastock Data\METAS\DXY0”,C);D2:=11; {ROC DAYS}a:=.16;b1:=.2;b2:=.175;b3:=-.5;ROCY:=ROC(C,D2,%);ROC1:=ROC(SEC1,D2,%);ROC2:=ROC(SEC2,D2,%);ROC3:=ROC(SEC3,D2,%);PRED:=a+b1∗ ROC1+b2∗ ROC2+b3∗ ROC3;DIVERG1:=(PRED-ROCY)∗ 10;DIVERG:=Mov(DIVERG1,3,E);IM:=(Mov(DIVERG - LLV(DIVERG,300), 3,S) ∗ 100)/(Mov(HHV(DIVERG,300) - LLV(DIVERG,300), 3,S));ALERT(DIVERG>0,3) AND STOCH(5,3)>MOV(STOCH(5,3),5,S) AND HHV(IM,4)>60 AND IM<REF(IM,-1)LRS Double (SLV-DXY)BuySEC1:=Security(“C:\Metastock Data\METAS\SLV”,C);SEC2:=Security(“C:\Metastock Data\METAS\DXY0”,C);D1:=20;{LRS SEC1};D2:=30;{LRS SEC2};D3:=20;{LRS GOLD};sY:=Stdev(C,300)/Mov(C,300,S);s1:=Stdev(SEC1,300))/Mov(SEC1,300,S);s2:=Stdev(SEC2,300))/Mov(SEC2,300,S);rY1:=Correl(SEC1,C,300,0);rY2:=Correl(SEC2,C,300,0);r12:=Correl(SEC1,SEC2,300,0);rY12:=(rY1-rY2∗ r12)/Sqrt(1-r12∗ r12);rY21:=(rY2-rY1∗ r12)/Sqrt(1-r12∗ r12);LRS1:=LinRegSlope(SEC1,D1)/Abs(Ref(SEC1,-D1+1))∗ 100;LRS2:=LinRegSlope(SEC2,D2)/Abs(Ref(SEC2,-D2+1))∗ 100;LRS:=LinRegSlope(C,D3)/Abs(Ref(C,-D3+1))∗ 100;DIVERG1:=(rY12∗ sY/s1∗ LRS1+rY21∗ sY/s2∗ LRS2-LRS)∗ 100;DIVERG:=Mov(DIVERG1,3,E);IM:=(Mov(DIVERG - LLV(DIVERG,200), 3,S) ∗ 100)/(Mov(HHV(DIVERG,200) - LLV(DIVERG,200), 3,S));DIVERG>0 AND ALERT(CROSS(70,IM),4) AND STOCH(5,3)>MOV(STOCH(5,3),3,S)
Appendix A
317
SellSEC1:=Security(“C:\Metastock Data\METAS\SLV”,C);SEC2:=Security(“C:\Metastock Data\METAS\DXY0”,C);D1:=20;{LRS SEC1};D2:=30;{LRS SEC2};D3:=20;{LRS GOLD};sY:=Stdev(C,300)/Mov(C,300,S);s1:=Stdev(SEC1,300))/Mov(SEC1,300,S);s2:=Stdev(SEC2,300))/Mov(SEC2,300,S);rY1:=Correl(SEC1,C,300,0);rY2:=Correl(SEC2,C,300,0);r12:=Correl(SEC1,SEC2,300,0);rY12:=(rY1-rY2∗ r12)/Sqrt(1-r12∗ r12);rY21:=(rY2-rY1∗ r12)/Sqrt(1-r12∗ r12);LRS1:=LinRegSlope(SEC1,D1)/Abs(Ref(SEC1,-D1+1))∗ 100;LRS2:=LinRegSlope(SEC2,D2)/Abs(Ref(SEC2,-D2+1))∗ 100;LRS:=LinRegSlope(C,D3)/Abs(Ref(C,-D3+1))∗ 100;DIVERG1:=(rY12∗ sY/s1∗ LRS1+rY21∗ sY/s2∗ LRS2-LRS)∗ 100;DIVERG:=Mov(DIVERG1,3,E);IM:=(Mov(DIVERG - LLV(DIVERG,200), 3,S) ∗ 100)/(Mov(HHV(DIVERG,200) - LLV(DIVERG,200), 3,S));STOCH(15,3)<MOV(STOCH(15,3),5,S) AND HHV(STOCH(15,3),3)>80 ANDLLV(IM,4)<7ShortSEC1:=Security(“C:\Metastock Data\METAS\SLV”,C);SEC2:=Security(“C:\Metastock Data\METAS\DXY0”,C);D1:=20;{LRS SEC1};D2:=30;{LRS SEC2};D3:=20;{LRS GOLD};sY:=Stdev(C,300)/Mov(C,300,S);s1:=Stdev(SEC1,300)/Mov(SEC1,300,S);s2:=Stdev(SEC2,300)/Mov(SEC2,300,S);rY1:=Correl(SEC1,C,300,0);rY2:=Correl(SEC2,C,300,0);r12:=Correl(SEC1,SEC2,300,0);rY12:=(rY1-rY2∗ r12)/Sqrt(1-r12∗ r12);rY21:=(rY2-rY1∗ r12)/Sqrt(1-r12∗ r12);LRS1:=LinRegSlope(SEC1,D1)/Abs(Ref(SEC1,-D1+1))∗ 100;LRS2:=LinRegSlope(SEC2,D2)/Abs(Ref(SEC2,-D2+1))∗ 100;LRS:=LinRegSlope(C,D3)/Abs(Ref(C,-D3+1))∗ 100;DIVERG1:=(rY12∗ sY/s1∗ LRS1+rY21∗ sY/s2∗ LRS2-LRS)∗ 100;DIVERG:=Mov(DIVERG1,3,E);IM:=(Mov(DIVERG - LLV(DIVERG,200), 3,S) ∗ 100)/(Mov(HHV(DIVERG,200) - LLV(DIVERG,200), 3,S));
318
Intermarket Trading Strategies
DIVERG<-1 AND STOCH(5,3)<MOV(STOCH(5,3),5,S)AND ALERT(CROSS(IM,5),4) AND IM>REF(IM,-2)CoverSEC1:=Security(“C:\Metastock Data\METAS\SLV”,C);SEC2:=Security(“C:\Metastock Data\METAS\DXY0”,C);D1:=20;{LRS SEC1};D2:=30;{LRS SEC2};D3:=20;{LRS GOLD};sY:=Stdev(C,300)/Mov(C,300,S);s1:=Stdev(SEC1,300))/Mov(SEC1,300,S);s2:=Stdev(SEC2,300))/Mov(SEC2,300,S);rY1:=Correl(SEC1,C,300,0);rY2:=Correl(SEC2,C,300,0);r12:=Correl(SEC1,SEC2,300,0);rY12:=(rY1-rY2∗ r12)/Sqrt(1-r12∗ r12);rY21:=(rY2-rY1∗ r12)/Sqrt(1-r12∗ r12);LRS1:=LinRegSlope(SEC1,D1)/Abs(Ref(SEC1,-D1+1))∗ 100;LRS2:=LinRegSlope(SEC2,D2)/Abs(Ref(SEC2,-D2+1))∗ 100;LRS:=LinRegSlope(C,D3)/Abs(Ref(C,-D3+1))∗ 100;DIVERG1:=(rY12∗ sY/s1∗ LRS1+rY21∗ sY/s2∗ LRS2-LRS)∗ 100;DIVERG:=Mov(DIVERG1,3,E);IM:=(Mov(DIVERG - LLV(DIVERG,200), 3,S) ∗ 100)/(Mov(HHV(DIVERG,200) - LLV(DIVERG,200), 3,S));ALERT(DIVERG>0,3) AND STOCH(5,3)>MOV(STOCH(5,3),5,S) ANDHHV(IM,4)>55 AND IM<ref(IM,-1)LRS Double (XAU-DXY)BuySEC1:=Security(“C:\Metastock Data\METAS\XAU”,C);SEC2:=Security(“C:\Metastock Data\METAS\DXY0”,C);D1:=20;{LRS SEC1};D2:=30;{LRS SEC2};D3:=20;{LRS GOLD};sY:=Stdev(C,300)/Mov(C,300,S);s1:=Stdev(SEC1,300))/Mov(SEC1,300,S);s2:=Stdev(SEC2,300))/Mov(SEC2,300,S);rY1:=Correl(SEC1,C,300,0);rY2:=Correl(SEC2,C,300,0);r12:=Correl(SEC1,SEC2,300,0);rY12:=(rY1-rY2∗ r12)/Sqrt(1-r12∗ r12);rY21:=(rY2-rY1∗ r12)/Sqrt(1-r12∗ r12);LRS1:=LinRegSlope(SEC1,D1)/Abs(Ref(SEC1,-D1+1))∗ 100;
Appendix A
319
LRS2:=LinRegSlope(SEC2,D2)/Abs(Ref(SEC2,-D2+1))∗ 100;LRS:=LinRegSlope(C,D3)/Abs(Ref(C,-D3+1))∗ 100;DIVERG1:=(rY12∗ sY/s1∗ LRS1+rY21∗ sY/s2∗ LRS2-LRS)∗ 100;DIVERG:=Mov(DIVERG1,3,E);IM:=(Mov(DIVERG - LLV(DIVERG,300), 3,S) ∗ 100)/(Mov(HHV(DIVERG,300) - LLV(DIVERG,300), 3,S));DIVERG>0 AND ALERT(CROSS(70,IM),4) ANDSTOCH(5,3)>MOV(STOCH(5,3),3,S)SellSEC1:=Security(“C:\Metastock Data\METAS\XAU”,C);SEC2:=Security(“C:\Metastock Data\METAS\DXY0”,C);D1:=20;{LRS SEC1};D2:=30;{LRS SEC2};D3:=20;{LRS GOLD};sY:=Stdev(C,300)/Mov(C,300,S);s1:=Stdev(SEC1,300))/Mov(SEC1,300,S);s2:=Stdev(SEC2,300))/Mov(SEC2,300,S);rY1:=Correl(SEC1,C,300,0);rY2:=Correl(SEC2,C,300,0);r12:=Correl(SEC1,SEC2,300,0);rY12:=(rY1-rY2∗ r12)/Sqrt(1-r12∗ r12);rY21:=(rY2-rY1∗ r12)/Sqrt(1-r12∗ r12);LRS1:=LinRegSlope(SEC1,D1)/Abs(Ref(SEC1,-D1+1))∗ 100;LRS2:=LinRegSlope(SEC2,D2)/Abs(Ref(SEC2,-D2+1))∗ 100;LRS:=LinRegSlope(C,D3)/Abs(Ref(C,-D3+1))∗ 100;DIVERG1:=(rY12∗ sY/s1∗ LRS1+rY21∗ sY/s2∗ LRS2-LRS)∗ 100;DIVERG:=Mov(DIVERG1,3,E);IM:=(Mov(DIVERG - LLV(DIVERG,300), 3,S) ∗ 100)/(Mov(HHV(DIVERG,300) - LLV(DIVERG,300), 3,S));STOCH(15,3)<MOV(STOCH(15,3),5,S) AND HHV(STOCH(15,3),3)>80 ANDLLV(IM,4)<10ShortSEC1:=Security(“C:\Metastock Data\METAS\XAU”,C);SEC2:=Security(“C:\Metastock Data\METAS\DXY0”,C);D1:=20;{LRS SEC1};D2:=30;{LRS SEC2};D3:=20;{LRS GOLD};sY:=Stdev(C,300)/Mov(C,300,S);s1:=Stdev(SEC1,300))/Mov(SEC1,300,S);s2:=Stdev(SEC2,300))/Mov(SEC2,300,S);rY1:=Correl(SEC1,C,300,0);
320
Intermarket Trading Strategies
rY2:=Correl(SEC2,C,300,0);r12:=Correl(SEC1,SEC2,300,0);rY12:=(rY1-rY2∗ r12)/Sqrt(1-r12∗ r12);rY21:=(rY2-rY1∗ r12)/Sqrt(1-r12∗ r12);LRS1:=LinRegSlope(SEC1,D1)/Abs(Ref(SEC1,-D1+1))∗ 100;LRS2:=LinRegSlope(SEC2,D2)/Abs(Ref(SEC2,-D2+1))∗ 100;LRS:=LinRegSlope(C,D3)/Abs(Ref(C,-D3+1))∗ 100;DIVERG1:=(rY12∗ sY/s1∗ LRS1+rY21∗ sY/s2∗ LRS2-LRS)∗ 100;DIVERG:=Mov(DIVERG1,3,E);IM:=(Mov(DIVERG - LLV(DIVERG,300), 3,S) ∗ 100)/(Mov(HHV(DIVERG,300) - LLV(DIVERG,300), 3,S));DIVERG<-1 AND STOCH(5,3)<MOV(STOCH(5,3),5,S)AND ALERT(CROSS(IM,15),4) AND IM>REF(IM,-2)CoverSEC1:=Security(“C:\Metastock Data\METAS\XAU”,C);SEC2:=Security(“C:\Metastock Data\METAS\DXY0”,C);D1:=20;{LRS SEC1};D2:=30;{LRS SEC2};D3:=20;{LRS GOLD};sY:=Stdev(C,300)/Mov(C,300,S);s1:=Stdev(SEC1,300))/Mov(SEC1,300,S);s2:=Stdev(SEC2,300))/Mov(SEC2,300,S);rY1:=Correl(SEC1,C,300,0);rY2:=Correl(SEC2,C,300,0);r12:=Correl(SEC1,SEC2,300,0);rY12:=(rY1-rY2∗ r12)/Sqrt(1-r12∗ r12);rY21:=(rY2-rY1∗ r12)/Sqrt(1-r12∗ r12);LRS1:=LinRegSlope(SEC1,D1)/Abs(Ref(SEC1,-D1+1))∗ 100;LRS2:=LinRegSlope(SEC2,D2)/Abs(Ref(SEC2,-D2+1))∗ 100;LRS:=LinRegSlope(C,D3)/Abs(Ref(C,-D3+1))∗ 100;DIVERG1:=(rY12∗ sY/s1∗ LRS1+rY21∗ sY/s2∗ LRS2-LRS)∗ 100;DIVERG:=Mov(DIVERG1,3,E);IM:=(Mov(DIVERG - LLV(DIVERG,300), 3,S) ∗ 100)/(Mov(HHV(DIVERG,300) - LLV(DIVERG,300), 3,S));ALERT(DIVERG>0,3) AND STOCH(5,3)>MOV(STOCH(5,3),5,S) ANDHHV(IM,4)>70 AND IM<ref(IM,-1)Regression Double (XAU-DXY)BuySEC1:=Security(“C:\Metastock Data\METAS\XAU”,C);
Appendix A
321
SEC2:=Security(“C:\Metastock Data\METAS\DXY0”,C);D1:=500; {REGRESSION DAYS}D2:=11; {ROC DAYS}ROCY:=ROC(C,D2,%);ROC1:=ROC(SEC1,D2,%);ROC2:=ROC(SEC2,D2,%);sY:=Stdev(ROCY,D1);s1:=Stdev(ROC1,D1);s2:=Stdev(ROC2,D1);rY1:=Correl(ROC1,ROCY,D1,0);rY2:=Correl(ROC2,ROCY,D1,0);r12:=Correl(ROC1,ROC2,D1,0);b1:=(rY1-rY2∗ r12)/(1-r12∗ r12)∗ (sY/s1);b2:=(rY2-rY1∗ r12)/Sqrt(1-r12∗ r12)∗ (sY/s2);a:=Mov(ROCY,D1,S)-b1∗ Mov(ROC1,D1,S)-b2∗ Mov(ROC2,D1,S);PRED:=a+b1∗ ROC1+b2∗ ROC2;DIVERG:=(PRED-ROCY)∗ 10;DIVERG:=Mov(DIVERG,3,E);IM:=(Mov(DIVERG - LLV(DIVERG,200), 3,S) ∗ 100)/(Mov(HHV(DIVERG,200) - LLV(DIVERG,200), 3,S));R2:= b1∗ s1/sY∗ rY1+b2∗ s2/sY∗ rY2;DIVERG>1 AND ALERT(CROSS(80,IM),4) AND STOCH(5,3)>MOV(STOCH(5,3),3,S) and R2>.46 AND (ADX(18) <28 or LinRegSlope(adx(18),5)<0)SellSEC1:=Security(“C:\Metastock Data\METAS\XAU”,C);SEC2:=Security(“C:\Metastock Data\METAS\DXY0”,C);D1:=500; {REGRESSION DAYS}D2:=11; {ROC DAYS}ROCY:=ROC(C,D2,%);ROC1:=ROC(SEC1,D2,%);ROC2:=ROC(SEC2,D2,%);sY:=Stdev(ROCY,D1);s1:=Stdev(ROC1,D1);s2:=Stdev(ROC2,D1);rY1:=Correl(ROC1,ROCY,D1,0);rY2:=Correl(ROC2,ROCY,D1,0);r12:=Correl(ROC1,ROC2,D1,0);b1:=(rY1-rY2∗ r12)/(1-r12∗ r12)∗ (sY/s1);b2:=(rY2-rY1∗ r12)/Sqrt(1-r12∗ r12)∗ (sY/s2);a:=Mov(ROCY,D1,S)-b1∗ Mov(ROC1,D1,S)-b2∗ Mov(ROC2,D1,S);PRED:=a+b1∗ ROC1+b2∗ ROC2;DIVERG:=(PRED-ROCY)∗ 10;DIVERG:=Mov(DIVERG,3,E);
322
Intermarket Trading Strategies
IM:=(Mov(DIVERG - LLV(DIVERG,200), 3,S) ∗ 100)/(Mov(HHV(DIVERG,200) - LLV(DIVERG,200), 3,S));STOCH(15,3)<MOV(STOCH(15,3),5,S) AND LLV(IM,4)<15OR (DIVERG<-25 AND ALERT(CROSS(MOV(STOCH(15,3),4,S), STOCH(15,3)), 3) AND ALERT(CROSS(MOV(STOCH(50,3),4,S), STOCH(50,3)), 3)AND HHV(STOCH(50,3),3)>80)ShortSEC1:=Security(“C:\Metastock Data\METAS\XAU”,C);SEC2:=Security(“C:\Metastock Data\METAS\DXY0”,C);D1:=500; {REGRESSION DAYS}D2:=11; {ROC DAYS}ROCY:=ROC(C,D2,%);ROC1:=ROC(SEC1,D2,%);ROC2:=ROC(SEC2,D2,%);sY:=Stdev(ROCY,D1);s1:=Stdev(ROC1,D1);s2:=Stdev(ROC2,D1);rY1:=Correl(ROC1,ROCY,D1,0);rY2:=Correl(ROC2,ROCY,D1,0);r12:=Correl(ROC1,ROC2,D1,0);b1:=(rY1-rY2∗ r12)/(1-r12∗ r12)∗ (sY/s1);b2:=(rY2-rY1∗ r12)/Sqrt(1-r12∗ r12)∗ (sY/s2);a:=Mov(ROCY,D1,S)-b1∗ Mov(ROC1,D1,S)-b2∗ Mov(ROC2,D1,S);PRED:=a+b1∗ ROC1+b2∗ ROC2;DIVERG:=(PRED-ROCY)∗ 10;DIVERG:=Mov(DIVERG,3,E);IM:=(Mov(DIVERG - LLV(DIVERG,200), 3,S) ∗ 100)/(Mov(HHV(DIVERG,200) - LLV(DIVERG,200), 3,S));DIVERG<-4 AND STOCH(5,3)<MOV(STOCH(5,3),5,S)AND ALERT(CROSS(IM,5),4) AND IM>REF(IM,-2)CoverSEC1:=Security(“C:\Metastock Data\METAS\XAU”,C);SEC2:=Security(“C:\Metastock Data\METAS\DXY0”,C);D1:=500; {REGRESSION DAYS}D2:=11; {ROC DAYS}ROCY:=ROC(C,D2,%);ROC1:=ROC(SEC1,D2,%);ROC2:=ROC(SEC2,D2,%);sY:=Stdev(ROCY,D1);s1:=Stdev(ROC1,D1);s2:=Stdev(ROC2,D1);rY1:=Correl(ROC1,ROCY,D1,0);rY2:=Correl(ROC2,ROCY,D1,0);
Appendix A
323
r12:=Correl(ROC1,ROC2,D1,0);b1:=(rY1-rY2∗ r12)/(1-r12∗ r12)∗ (sY/s1);b2:=(rY2-rY1∗ r12)/Sqrt(1-r12∗ r12)∗ (sY/s2);a:=Mov(ROCY,D1,S)-b1∗ Mov(ROC1,D1,S)-b2∗ Mov(ROC2,D1,S);PRED:=a+b1∗ ROC1+b2∗ ROC2;DIVERG:=(PRED-ROCY)∗ 10;DIVERG:=Mov(DIVERG,3,E);IM:=(Mov(DIVERG - LLV(DIVERG,200), 3,S) ∗ 100)/(Mov(HHV(DIVERG,200) - LLV(DIVERG,200), 3,S));ALERT(DIVERG>0,3) AND STOCH(5,3)>MOV(STOCH(5,3),5,S) AND HHV(IM,4)>55 AND IM<REF(IM,-1)
A.3 METASTOCK CODE FOR THE S&P SYSTEMS DESCRIBEDIN CHAPTER 12SPY Daily Regression System(Copyright Markos Katsanos 2007)To recreate the tests click on enhanced system tester, click on new system and type thebuy and sell code. Then to run the test, click on new simulation, next, add securities,select SPY, select periodicity daily, click on next, type in initial equity 40000, selecttransaction cost 20000, select only long trades. Click on more. . ., fill in interestrate 4 %, and fill in 10 points per transaction for the commissions. Click on tradeexecution, uncheck realistic market prices and select buy price and sell price at open.Then fill in 1 day for the delay.LongSEC2:=Security(“C:\Metastock Data\INTERMARKET\T2108”,C);D1:=400; {REGRESSION DAYS}D2:=20; {ROC DAYS}RS1:=ROC(C,D2,%);RS2:=ROC(SEC2,D2,%);b:=Correl(RS1,RS2,D1,0)∗ Stdev(RS1,D1)/Stdev(RS2,D1);a:=mov(RS1,D1,S)-b∗ MOV(RS2,D1,S);pred:=b∗ RS2+a;DIVERG:=(PRED-RS1);DIVERG:=Mov(DIVERG,3,E);IM:=(Mov(DIVERG - LLV(DIVERG,40), 3,S) ∗ 100)/(Mov(HHV(DIVERG,40) - LLV(DIVERG,40), 3,S));HHV(DIVERG,2)>1 AND ALERT(CROSS(80,IM),5) AND STOCH(5,3)>MOV(STOCH(5,3),3,S) AND ROC(SEC2,3,%)>0
324
Intermarket Trading Strategies
SellSEC2:=Security(“C:\Metastock Data\INTERMARKET\T2108”,C);D1:=400; {REGRESSION DAYS}D2:=20; {ROC DAYS}RS1:=ROC(C,D2,%);RS2:=ROC(SEC2,D2,%);b:=Correl(RS1,RS2,D1,0)∗ Stdev(RS1,D1)/Stdev(RS2,D1);a:=mov(RS1,D1,S)-b∗ MOV(RS2,D1,S);pred:=b∗ RS2+a;DIVERG1:=(PRED-RS1);DIVERG:=Mov(DIVERG1,3,E);IM:=(Mov(DIVERG - LLV(DIVERG,40), 3,S) ∗ 100)/(Mov(HHV(DIVERG,40) - LLV(DIVERG,40), 3,S));DIVERG<0 AND STOCH(5,3)<MOV(STOCH(5,3),4,S) AND LLV(IM,4)<15AND IM>REF(IM,-1) AND ROC(SEC2,3,%)<0Sell shortSEC2:=Security(“C:\Metastock Data\INTERMARKET\T2108”,C);HHV(SEC2,9)>72 AND SEC2