Formula ALWAYS gives me a TRUE answer?

Hi experts,

I'd like to know why this formula ALWAYS gives me a TRUE answer?

Thank you.
Yves L.

_SECTION_BEGIN("Trend MA en Hausse ");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

function MAH(Ind) 
{ bon= (Ind>=Ref(Ind,-1) OR Ind>=Ref(Ind,-2) OR Ind>=Ref(Ind,-3) OR Ind>=Ref(Ind,-5) OR
	Ind>=Ref(Ind,-7) OR Ind>=Ref(Ind,-9) OR Ind>=Ref(Ind,-11) OR Ind>=Ref(Ind,-15)) ;
	 return bon ; } 

MA20= MA(C,20) ;		MA50= MA(C,50) ;
MA100= MA(C,100) ;	MA200= MA(C,200) ;

MA100H= MAH(100) ;
MA200H= MAH(200) ;
/*
UpTrend= (MA100>=MA200 OR MA200H OR MA100H) ;
downTrend= Uptrend==0 ;
*/
Plot(MA100H, "MA100", colorBlue );

_SECTION_END();type or paste code here

You are passing SCALAR value (100) to the function that checks if input is greater OR EQUAL to same input N-bar ago. Obviously since condition is >= (greater or EQUAL) it will evaluate to TRUE always because Ref(X, -N ) from SCALAR X value is always X and X >= X is always true.

To get better understanding of what is happening in your code and how functions work, use advice given here: How do I debug my formula?

1 Like