ZigZag with Top and Bottom

Hi expert,

I'm trying to write a formula that will give me:

  • Brake Out of Bollinger Bands + Volume

  • Pull back under the MA200

I wrote part of the formula.

To do this, I use ZigZag (ChZZ – line 29)

With ChZZ I can easily find the ZZ for my upward and downward wave

But I can't use ChZZ (Ex.: Trough(C, ChZZ, 1) line 44) because AB tells me:

Error 5. The function expected a NUMBER here, but found an ARRAY

I would like to know the length of my wave (LongV)

To validate that the bottom of the start of the wave is below the MA200

And find the HHV(Macd(), LongV) before the start of this wave

Thank you Expert

Yves L.

/*      BrOut BB Daily et PB under MA200	*/

V20= MA(V,20) ;	
V50= IIf(IsNull(MA(V,50)),V20,MA(V,50)) ;
V100= IIf(IsNull(MA(V,100)),V50,MA(V,100)) ;
V200= IIf(IsNull(MA(V,200)),V100,MA(V,200)) ;
VolMin= Min(Min(V20,V50),Min(V100,V200)) ;
Plot(VolMin,"V-Min",colorTeal,styleOwnScale );
function BBT(Ind,P)	{ bon= BBandTop(Ind,P,2) ; return bon ; } ;
function CrBB(Ind,P)	{ bon= Cross(C,BBT(Ind,P)) ; return bon ; } ;
function CrBbVol(Ind,P)	{ bon= CrBB(Ind,P) AND V>=VolMin ;  return bon ; } ;
CrBbD= (CrBBVol(C,15) OR CrBBVol(C,20)) AND V>= 1.15*VolMin ;	
Plot(CrBbD,"CrBB-D+Vol",colorblue,styleOwnScale );
MA200= MA(C,200) ;

CrSto= Cross(StochD(9,3,3),StochK(9,3)) ;
//Plot(CrSto,"Cr(Stock-NA)",colorteal,styleOwnScale );
LongCrBbD= BarsSince(CrBbD) ;
Plot(LongCrBbD,"Long-CrBB",colorblue,styleOwnScale );
Haut= HHV(C,LongCrBbD+2) ;
Plot(Haut,"Haut)",colorRed,styleOwnScale );
// Limiter la longueur du haut ???????????????
BarH= HHVBars(C,LongCrBbD+2) ;
Plot(BarH,"LongHaut",colorRed,styleOwnScale );
BarBas= LLVBars(C, BarH) ;
Plot(BarBas,"LongBas)",colorBlue,styleOwnScale );
// chercher le bon ZZ
ChZZ= 	IIf(Haut== Peak(C,60,1),60,			IIf(Haut== Peak(C,55,1),55,
		IIf(Haut== Peak(C,50,1),50,			IIf(Haut== Peak(C,45,1),45,
		IIf(Haut== Peak(C,40,1),40,			IIf(Haut== Peak(C,35,1),35,
		IIf(Haut== Peak(C,30,1),30,			IIf(Haut== Peak(C,27,1),27,
		IIf(Haut== Peak(C,25,1),25,			IIf(Haut== Peak(C,22,1),22,	
		IIf(Haut== Peak(C,20,1),20,			IIf(Haut== Peak(C,17,1),17,
		IIf(Haut== Peak(C,15,1),15,			IIf(Haut== Peak(C,12,1),12,	
		IIf(Haut== Peak(C,10,1),10,			IIf(Haut== Peak(C,9,1),9,
		IIf(Haut== Peak(C,8,1),8,			IIf(Haut== Peak(C,7,1),7,
		IIf(Haut== Peak(C,6,1),6,			IIf(Haut== Peak(C,5,1),5,
		IIf(Haut== Peak(C,4,1),4,			IIf(Haut== Peak(C,3,1),3,		
									0)))))))))))))))))))))) ;		
Plot(ChZZ,"\nZZ",colorCustom12,styleOwnScale|styleDashed );

//  Bug line 44
//Plot(  Trough(C, ChZZ  , 1),"Bas",colorBlack,styleOwnScale );


HautOK= Ref(C,-BarH) >= Ref(Ma200,-BarH) ; // Top over MA200
LongBas=LLVBars(C, BarH) ;
BasOK= Ref(C,-LongBas)<= Ref(Ma200,-LongBas) ;  // Low under MA200
CrStoOK= CrSto AND HautOK AND BasOK ;  

Buy=CrStoOK ;
Plot(Buy,"Buy",colorBlack,styleOwnScale|styleThick );
//Trough(ARRAY, change, n = 1) 
_SECTION_END();
type or paste code here

Isn't your question already answered in existing thread:

Thank for your help and the formula

In my formula ChZZ(line 29), search the good Zigzag

But I can’t use it, because, (Error 5):

Error 5. The function expected a NUMBER here, but found an ARRAY

How transforming an ARRAY in NUMBER

Thank’s expert

Yves L.

The code that you posted does not generate Error 5.

The code in my first mail is O.K.
because, I’m use 2 backslash when I’m start les line 43

//Plot( Trough(C, ChZZ , 1),"Bas",colorBlack,styleOwnScale );

If you delete this 2 backslash you have the ERROR 5

He have 2 or 3 other thinks of I Can’t made it?

I would like to know the length of my wave (LongV)

To validate that the bottom of the start of the wave is below the MA200

And find the HHV(Macd(), LongV) before the start of this wave

Thank you Expert

Yves L.