Problem with IF, IIF or for

In the formula below

At the line 6, I’m use The ZigZag=20 for plot when Close Cross trendlineDown with Volume

I would like to replace line 6

By lines 7 to 9,

Which would allow me in a Scan, To find ALL the Cross trendlineDown with Volume with different ZigZag In one step

Thank’s

YvesLaliberte

_SECTION_BEGIN("CrTrLnDn+3*Vol");
V20= MA(V,20) ;		V50= MA(V,50) ;		V100= MA(V,100) ;	V200= MA(V,200) ;
VolM= Min(Min(V20,V50), Min(V100,V200) ) ;
VolOK= V>3*VolM ;

ZZ= 20 ;
/*i = 0 ;
ZZ= IIf( C<1 , for( i= 10; i< 180; i+10 ) ,
	IIf( C>=1 , for( i= 10; i< 100; i+5 ) , o ))  ;			*/

function ValPk(Size,P1)
{
	Prix=LastValue(Peak(C,Size,P1)); 
	return Prix ;
}
function NextPeak(S,P)  // Trouve le prochain peak +>=
{
p= ValPk(S,P) ;	
P2= 	IIf(	P< ValPk(S,2),2,			IIf(	P< ValPk(S,3),3,
		IIf(	P< ValPk(S,4),4,			IIf(	P< ValPk(S,5),5,
		IIf(	P< ValPk(S,6),6,			IIf(	P< ValPk(S,7),3,
		IIf(	P< ValPk(S,8),8,			IIf(	P< ValPk(S,9),9,
		IIf(	P< ValPk(S,10),10,		IIf(	P< ValPk(S,11),11,
		IIf(	P< ValPk(S,12),12,		IIf(	P< ValPk(S,13),13,
		IIf(	P< ValPk(S,14),14,		IIf(	P< ValPk(S,15),15,
		IIf(	P< ValPk(S,16),16,		IIf(	P< ValPk(S,17),13,
		IIf(	P< ValPk(S,18),18,		IIf(	P< ValPk(S,19),19,
		IIf(	P< ValPk(S,20),20,	0 ))))))))))))))))))) ;
return P2 ; 
}
function CrTrDn(Size,P1,P2)
{	/* dessine TrendLineDown si VOL.   */
	y0=LastValue(Peak(C,Size,P2)); 
	y1=LastValue(Peak(C,Size,P1)); 
	x0=BarCount - 1 - LastValue(PeakBars(C,Size,P2)); 
	x1=BarCount - 1 - LastValue(PeakBars(C,Size,P1));
	Line = LineArray( x0, y0, x1, y1, 1 ); 
	CrTrend= IIf( Cross(C,Line) AND V>=VolOK,	1	,	 0);
//		Plot( Line, "\nTrend line", colorBlue,styleNoRescale,4+8 ), 0); 
	return CrTrend ;   //             OR Size ??????????
}

function TrDn(S,P) {OK= CrTrDn(S,P,NextPeak(S,P)) ; return OK ; }

CrTrLnD =	IIf(C<4.9999,(TrDn(25,1) OR TrDn(25,2) OR TrDn(20,1) OR TrDn(20,2) OR
							TrDn(15,1) OR TrDn(15,2) OR TrDn(10,1) OR TrDn(10,2) OR
							TrDn(8,1) OR TrDn(8,2) OR TrDn(7,1) OR TrDn(7,2) OR
							TrDn(6,1) OR TrDn(6,2) OR TrDn(5,1) OR TrDn(5,2)),
	IIf(C>5 AND C<19.9999,(TrDn(25,1) OR TrDn(25,2) OR TrDn(20,1) OR TrDn(20,2) OR
							TrDn(15,1) OR TrDn(15,2) OR TrDn(10,1) OR TrDn(10,2) OR
							TrDn(7,1) OR TrDn(7,2) OR TrDn(5,1) OR TrDn(5,2) OR 
							TrDn(4,1) OR TrDn(4,2) OR TrDn(3,1) OR TrDn(3,2) OR TrDn(2,1) OR TrDn(2,2) ),	
	IIf(C>20 ,		(TrDn(15,1) OR TrDn(15,2) OR TrDn(10,1) OR TrDn(10,2) OR
							TrDn(7,1) OR TrDn(7,2) OR TrDn(5,1) OR TrDn(5,2) OR 
							TrDn(4,1) OR TrDn(4,2) OR TrDn(3,1) OR TrDn(3,2)OR
							TrDn(2,1) OR TrDn(2,2) OR TrDn(1,1) OR TrDn(1,2) ),		0)));

Plot(ZZ,"Zig",colorcustom12, styleOwnScale,styleThick ) ;
Plot(CrTrLnD,"CrTrDn-Daily",colorcustom12, styleOwnScale,styleThick ) ;
Buy= CrTrLnD ;
_SECTION_END();

@yveslaliberte , you need to make sure you understand the difference between the commands, and be able to "think like a dumb computer".

IF - is a Program Flow control statement.
i.e. IF(C<1) do a bunch of other commands

IFF - is a Function that returns a value or an array
i.e. IIF(C<1, 0, 1)

FOR - is a Loop control structure

Look in the HELP/User's Guide and check out the IIF function.

Hopefully this will lead you to what you need.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.