| 
 PureBytes Links 
Trading Reference Links 
 | 
The April and May 2005 issue of TASC has articles by Markos Katsanos 
on his Flags and Pennants Trading System.  The May issue has the 
Metastock code for the system in the article called, "Detecting 
Breakouts from Flags & Pennants".  I thought it would be interesting 
to try it out in AFL.  My AFL code is below with mistakes or my 
programming uncertainties which I have commented on (//AFL 
GURUS.....) and Markos Katsanos Metastock code is below my AFL for 
comparison.  The May issue also has code for exploration (columns) 
but I'll leave that for somebody with more knowledge of AFL to try.  
Hopefully, the corrected version of the AFL code can be submitted to 
the AFL Library
//AFL CODE FOR MARKOS KATSANOS "DETECTING BREAKOUTS FROM FLAGS AND 
PENNANTS
//Enter Long
ZZ = Zig(C,17); //AFL GURUS PLEASE CHECK TO SEE IF THIS LINE IS 
CORRECT VS METASTOCK CODE BELOW//
X = BarsSince(ZZ<Ref(ZZ,-1) AND Ref(ZZ,-1)> Ref(ZZ,-2));
X1 = LastValue(X) + 1;
X2 = X1 + 1;
SD = StDev(C,X2);
PERIOD = 22;
COEFF = 0.1;
intRA = log(H) - log(L);
VINTRA = StDev(intRA, PERIOD);
intER = log(Avg)-log(Ref(Avg,-1));
VINTER = StDev(intER,PERIOD);
CUTOFF = COEFF*(VINTER + VINTRA)*C;
MF = C - (H+L)/2 + Avg - Ref(Avg,-1);
MFV = IIf(MF>CUTOFF,V,IIf(MF<-CUTOFF,-V,0));
FVE = Sum(MFV,PERIOD)/MA(V,PERIOD)/PERIOD*100;
X1<21 AND X1>2 AND //CONDITION 1
Ref(LinRegSlope(C,13)/Ref(C,-13)*100, -X1)>2.2 //CONDITION 2
AND Ref(LinRegSlope(C,X2)/Ref(C,-X2),-1)*100<.2
AND LinRegSlope(C,X1)/Ref(C,-X1)>-1.2 //CONDITION 3
AND Ref(LinRegSlope(V,X2)/Ref(V,-X2),-1)*100<-2 //CONDITION 4
AND Ref(LinRegSlope(SD,X1),-1)<0 //CONDITION 5
AND StochK(20,3)>55 AND ADX(10)>30 //CONDITION 6
AND FVE>10 AND VFI>-3 //CONDITION 7// AFL GURUS - HOW DO I 
INCORPORATE VFI - METASTOCK CODE FOR VFI IS BELOW (FROM MARKOS 
ARTICLE)//
AND C>Ref(C,-1) AND C>O; //CONDITION 8
//SELL ORDER
D1 = ApplyStop(stopTypeNBar,stopModeBars); D2 = LastValue(D1); //AFL 
GURUS - I NEED HELP WITH THIS//
zz = Zig(Ref(C,-D2),17); //AFL GURUS - THIS NEEDS TO BE CHECKED//
X = BarsSince(ZZ<Ref(ZZ,-1) AND Ref(ZZ,-1)> Ref(ZZ,-2));
X1 = LastValue(X) + 1; //FLAG DURATION
C1 = LLV(C,(D2+40)); //POLE BASE
C2 = Ref(HHV(C,22),-D2); //POLE TOP
BREAK1 = ApplyStop(stopTypeNBar,stopModePercent); //AFL GURUS - HOW 
DO I CODE THIS//
POLE = (C2-C1)/C1*100; //POLE HEIGHT %
//EXIT CONDITIONS
BREAK1 > 1.94*POWER(POLE,.724) //EXIT CONDITION 1 PROFIT TARGET //AFL 
GURUS - IS THIS LINE CORRECT AGAINST METASTOCK CODE BELOW//
OR C<Ref(LLV(C,X1), -D2) //EXIT CONDITION 2 STOP LOSS ON BREAKING OF 
LOWER FLAG TRENDLINE
OR (D2>14 AND BREAK1<.25*POLE) //EXIT CONDITION 3 - INACTIVITY
OR (D2>3 AND C<.9*HHV(C,4)) //EXIT CONDITION 4 - TRAILING STOP LOSS
OR D2>24; //EXIT CONDITION 5 - TIME EXIT
//MARKOS KATSANOS METASTOCK CODE FOR DETECTING BREAKOUTS IN FLAGS AND 
PENNANTS//
//Enter Long
ZZ: = Zig(C,17,%);
X: = BarsSince(ZZ<Ref(ZZ,-1) AND Ref(ZZ,-1)> Ref(ZZ,-2));
X1: = LastValue(X) + 1; //FLAG DURATION
X2: = X1 + 1;
SD: = StDev(C,X2);
PERIOD: = 22;
COEFF: = 0.1;
INTRA: = log(H) - log(L);
VINTRA: = StDev(INTRA, PERIOD);
INTER: = log(Typical())-log(Ref(Typical(),-1));
VINTER: = StDev(INTER,PERIOD);
CUTOFF: = COEFF*(VINTER + VINTRA)*C;
MF = C - (H+L)/2 + Typical() - Ref(Typical(),-1);
FVE = Sum(If(MF>CUTOFF,+V,IF(MF<-CUTOFF,-V,0)),PERIOD)/Mov
(V,PERIOD,S)/PERIOD*100;
X1<21 AND X1>2 AND //CONDITION 1
Ref(LinRegSlope(C,13)/Ref(C,-13)*100, -X1)>2.2 //CONDITION 2
AND Ref(LinRegSlope(C,X2)/Ref(C,-X2),-1)*100<.2
AND LinRegSlope(C,X1)/Ref(C,-X1)>-1.2 //CONDITION 3
AND Ref(LinRegSlope(V,X2)/Ref(V,-X2),-1)*100<-2 //CONDITION 4
AND Ref(LinRegSlope(SD,X1),-1)<0 //CONDITION 5
AND Stoch(20,3)>55 AND ADX(10)>30 //CONDITION 6
AND FVE>10 AND Fml("VFI")>-3 //CONDITION 7 //AFL GURUS - CODE FOR VFI 
IS BELOW
AND C>Ref(C,-1) AND C>O; //CONDITION 8
//SELL ORDER
D1: = Simulation.CurrentPositionAge; D2: = LastValue(D1);
zz: = Zig(Ref(C,-D2),17,%);
X: = BarsSince(ZZ<Ref(ZZ,-1) AND Ref(ZZ,-1)> Ref(ZZ,-2));
X1: = LastValue(X) + 1; //FLAG DURATION
c1: = LLV(C,(D2+40)); //POLE BASE
c2: = Ref(HHV(C,22),-D2); //POLE TOP
BREAK1: = Simulation.CurrentPositionPerformance*100; 
POLE: = (C2-C1)/C1*100; //POLE HEIGHT %
//EXIT CONDITIONS
BREAK1 > 1.94*Power(Pole,.724) //EXIT CONDITION 1 PROFIT TARGET - (in 
article he has profit target as 1.94*pole^0.724)//
OR C<Ref(LLV(C,X1), -D2) //EXIT CONDITION 2 STOP LOSS ON BREAKING OF 
LOWER FLAG TRENDLINE
OR (D2>14 AND BREAK1<.25*POLE) //EXIT CONDITION 3 - INACTIVITY
OR (D2>3 AND C<.9*HHV(C,4)) //EXIT CONDITION 4 - TRAILING STOP LOSS
OR D2>24; //EXIT CONDITION 5 - TIME EXIT
//METASTOCK CODE FOR VFI FORMULA//
PERIOD: = Input("PERIOD FOR VFI",5,1300,130);
COEF: = .2;
VCOEF: = Input("MAX VOLUME CUTOFF",0,50,2.5);
INTER: = Log(Typical())-Log(Ref(Typical(),-1));
VINTER: = Stdev(INTER,30);
CUTOFF: = COEF*VINTER*C;
VAVE: = Ref(Mov(V,PERIOD,S),-1);
VMAX: = VAVE*VCOEF;
VC: = If(V<VMAX,V,VMAX);
MF: = Typical()-Ref(Typical(),-1);
VFI: = Sum(If(MF>CUTOFF,+VC,If(MF<-CUTOFF,-VC,0)),PERIOD)/VAVE;
Mov(VFI,3,E);
------------------------ Yahoo! Groups Sponsor --------------------~--> 
Has someone you know been affected by illness or disease?
Network for Good is THE place to support health awareness efforts!
http://us.click.yahoo.com/Rcy2bD/UOnJAA/cosFAA/GHeqlB/TM
--------------------------------------------------------------------~-> 
Please note that this group is for discussion between users only.
To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com
For other support material please check also:
http://www.amibroker.com/support.html
 
Yahoo! Groups Links
<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/
<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 
 |