Hello,
I obtained the following code from a Stocks and Commodities publication and have successfully used this on Metastock 16 for quite some time. I have attempted to transpose this Metastock Code to Pro Real Time V10.3 however I have failed to succeed in regards to the ZigZag function as V10.3 does not use arrays as I understand. Below is the filtering portion of the code and the PDF of the Stocks and Commodities document is attached.
Detects Breakouts from Flags and Pennants
Condition 1 Flag Duration
Condition 2 Flag Pole
Condition 3 Slope of Flag
Condition 4 Volume
Condition 5 Volitility
Condition 6 Stochastics & Avg Directional Movement Index
Condition 7 Money Flow AND FVE>10 AND Fml(“VFI”)>-3 {Condition 7}
Condition 8 Price
Filter
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;
COEF:=.1;
INTRA:=Log(H)-Log(L);
VINTRA:=Stdev(INTRA,PERIOD);
INTER:=Log(Typical())-Log(Ref(Typical(),-1));
VINTER:=Stdev(INTER,PERIOD);
CUTOFF:=COEF*(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}
AND C>Ref(C,-1) AND C>0 {Condition 8}
Added to my conversion list, please remind me if I still haven’t made it by August.
Here is the translated code, apart from the VFI condition (VolumeFlowIndex is not an instruction in PRT) , it should run fine.
percent = 5
ZZ=ZigZag[percent](close)
zzc = zz<zz[1] and zz[1]>zz[2]
if zzc then
startbar=barindex
endif
//X:=BarsSince(ZZ<Ref(ZZ,-1)AND Ref(ZZ,-1)>Ref(ZZ,-2));
x = max(1,min(barindex-startbar,254))
X1=X+1// {Flag Duration}
X2=X1+1
SD=Std[x2](Close)
PERIOD=22
COEF=1
INTRA=Log(High)-Log(Low)
VINTRA=Std[PERIOD](INTRA)
INTER=Log(Typicalprice)-Log(Typicalprice[1])
VINTER=Std[PERIOD](INTER)
CUTOFF=COEF*(VINTER+VINTRA)*Close
MF=Close-(High+Low)/2+Typicalprice-(Typicalprice[1])
//FVE=Sum(If(MF>CUTOFF,+V, If(MF<-CUTOFF, -V,0)),PERIOD)/Mov(V,PERIOD,S)/PERIOD*100;
FVE=0
for i = 0 to PERIOD-1 do
if MF[i]>CUTOFF[i] then
fve=fve+volume
endif
if MF[i]<-CUTOFF[i] then
fve=fve-volume
endif
next
fve=fve/average[PERIOD](volume)/period*100
C1 = X1<21 AND X1>2 //{Condition 1}
C2 = (LinearRegressionSlope[13](close)[x1]/(Close[13+x1])*100)>2.2 //{Condition 2}
C3 = (LinearRegressionSlope[x2](Close)[1]/(Close[X2+1]))*100<.2 AND LinearRegressionSlope[X1](close)/Close[X1]>-1.2//{Condition 3}
C4 = (LinearRegressionSlope[x2](Volume)[1]/(Volume[X2+1]))*100<-2 //{Condition 4}
C5 = (LinearRegressionSlope[X1](SD)[1])<0 //{Condition 5}
C6 = Stochastic[20,3]>55 AND ADX[10]>30 //{Condition 6}
C7 = FVE>10 //AND >-3 {Condition 7}
C8 = Close>Close[1] AND Close>0 //{Condition 8}
test = c1 and c2 and c3 and c4 and c5 and c6 and c7 and c8
screener[test]
Thanks Nic. Much appreciated on the quick turnaround.