Get the percentage of up and down days in a given range

Thanks for the quick reply! The min() did the trick and I just saw the same linked article about number of bars as well from another thread that I just read Limit to 200 barCount in loop .

Here is the corrected code now. I reckon there is no non-loop version of what I'm trying to do?

upDays = 0;
downDays = 0;

lookbackValue = Min(252, BarCount);

for( i = 1; i < lookbackValue; i++ )
{
	_TRACE("Array:" +i );
	_TRACE("Stock:" + Name() );
	_TRACE(" Close[BarCount- i ]:" +  Close[BarCount- i ] );
	_TRACE(" Close[ BarCount - 1 -i ]:" +  Close[ BarCount - 1 -i  ] );
   if ( Close[ BarCount- i ] > Close[ BarCount - 1 -i ] )
   {
	   upDays++;
   }
   else
   {
	   downDays++;
   }
}


totalDays = upDays + downDays;
upDayPercentage = upDays / totalDays;
downDayPercentage = downDays / totalDays;

Filter=1;
CustomBG = ColorHSB( 30, 50, 255 );
AddColumn(totalDays,"Combine total of days",1,colorDefault, customBG, 70);
AddColumn(upDays,"# of up days",1,colorDefault, customBG, 70);
AddColumn(upDayPercentage,"% of up days",1.2,colorDefault, customBG, 70);
AddColumn(downDays,"down",1,colorDefault, customBG, 70);
AddColumn(downDayPercentage,"% of down days",1.2,colorDefault, customBG, 70);