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.

Excuse me Tomasz,
But I did not receive a response to my last intervention
N.B. If I use: EndValue(Pe),
I'm lose more than 50% of the results
THANKS
Yves Laliberté

Please post entire code exactly as you use it, so I can copy-paste it directly without changing anything. Please follow this advice: How to ask a good question

I checked previously posted code and it did NOT generate any errors, so you might be using other formula than posted.

Here is my whole formula, M. Tomasz
On line 28 we look for the ZZ
On line 43, I try to use the ZZ found
And I get: Error 5. The function expected a NUMBER here, but found an ARRAY
N.B. If I use: EndValue(Pe), I'm losing more than 50% of the results
THANKS
Yves Laliberté

/*      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 43, Error 5. The function expected a NUMBER here, but found an ARRAY
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();

Trough() does not accept array in second argument, in other words the "change" argument must be constant, not variable.

I am not sure what you are trying to achieve but you might try this:

I Expert,

With ChZZ(line 29) I can easily find the ZZ for my upward and downward wave

//I'm plot the ChZZ to see the value and is good
Plot(ChZZ,"\nZZ",colorCustom12,styleOwnScale|styleDashed );

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
Plot( Trough(C, ChZZ , 1),"Bas",colorBlack,styleOwnScale );

I want to change the result of ChZZ(ARRAY) to NUMBER, for then
use it in:
Trough(C, ChZZ , 1)

Tank's
Yves Laliberté

I Expert,
In the first line of your answer you say:

  • How to make any function accepting variable
    We have a BIG problem !!!!!!!!

I don't want to transfer an ARRAY into a VARIABLE, but into a NUMBER!!!!!!

THANKS
Yves Laliberté

/*      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 43, Error 5. The function expected a NUMBER here, but found an ARRAY
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();

You can use
number = LastValue( array );
to get last value of any array as number
or
number = SelectedValue( array );
to get selected value of any array as number
or
number = array[ index ];
to get array value at specified index as number