Hi Expert,
I'm trying to write a formula that will give me stock prices that break up above the 3-day moving average (MA100, 200, and 300) and then fall back below that same 3-day moving average.
I wrote my formula using the ZigZag method because it's easier to access all the data points.
But I'm trying to understand why there's such a big difference between the M3MA result on line 16 and the M3MA on line 33.
I thought I would get roughly the same result.
Thanks,
Yves Laliberte
_SECTION_BEGIN("LHL Wave Under+Over+Under3MA");
P= 20 ; // Value of ZZ
MA100= Ma(C,100) ; MA200= Ma(C,200) ; MA300= Ma(C,300) ;
M3MA= ((Ma100+Ma200+MA300) /3) ;
function LHaut(Ind,Per,Pos) { bon= Peakbars(Ind,Per,Pos) ; return bon ; } ;
function PHaut(Ind,P,Pos) { bon= Peak(Ind,P,Pos) ; return bon ; } ;
//function PHaut(Ind,Long) { bon= Ref( Ind,-Long) ; return bon ; } ;
function PBp(Ind,P,Pos) { bon= trough(Ind,P,Pos) ; return bon ; } ;
function PBas(Ind,P,Pos) { bon= LLV(C,PeakBars(C,P,1)) ; return bon ; } ;
function BasOK(P) { bon= PBas(C,P,1)<= PBas(M3MA,P,1) ; return bon ; } ;
function HoOK(P) { bon= PHaut(C,P,1)>= PHaut(M3MA,P,1) ; return bon ; } ;
function BpOK(P) { bon= PbP(C,P,1)<= PbP(M3MA,P,1) ; return bon ; } ;
Plot(C,"Close",colorBlack,styleThick );
Plot(M3MA,"3MA",colorOrange,styleThick );
//P= 20 ;
CrM3MA= Cross(M3MA,C) AND BPOK(P) AND BasOK(P) ; // AND HoOK(P) ; //BUG
//CrM3MA= Cross(M3MA,C) AND BPOK(P) AND HoOK(P) AND BasOK(P) ;
Plot( CrM3MA,"CrB3MA",colorCustom12,styleLine |styleOwnScale|styleThick );
/*
Plot( PBp(C,P,1), "$BP", colorBlue,styleOwnScale|styleDashed );
Plot( PHaut(C,P,1), "$Haut", colorBlue,styleOwnScale|styleDashed );
Plot( PBas(C,P,1), "$Bas", colorBlack,styleOwnScale|styleDashed );
Plot(PHaut(C,P,1),"$Ho", colorBlack,styleOwnScale|styleDashed );
Plot(PHaut(M3MA,P,1),"$3MA", colorBlack,styleOwnScale|styleDashed );// BUG
*/
Plot(PHaut(C,P,1),"\n$Haut", colorDarkRed,styleOwnScale|styleDashed );
Plot(PHaut(M3MA,P,1),"$3MA", colorOrange,styleDashed|styleThick );
_SECTION_END();ype or paste code here

