# CrTrLnDn Week --> Daily

Hello,
I tried to write a formula that would give me when We cross the downward trend during the week on a graph in dayly
But the result is very different in day VS week

``````type or paste code here
``````

What is the error in my formula ?

``````_SECTION_BEGIN("Cross Trendline Down + Vol.Divers");
/* dessine TrendLineDown si Vol. OK		*/

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), 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 ; }

Buy=	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)));
V10= MA(V,10) ;		V20= MA(V,20) ;
V50= MA(V,50) ;		V100= MA(V,100) ;
VolMM= Min(Min(V10,V20),Min(V50,V100)) ;
Vmin = 500000 ;
VolOK = (V>(1.5*VolMM)) AND (V>Vmin) ;

TimeFrameSet( inweekly ); // switch now to hourly
TimeFrameRestore(); // restore time frame to original
CrW= TimeFrameExpand( CrTrLn_Week, inweekly) ;