This code sets streak to 1 if the price hasn't moved. Setting streak to 0 would seem more logical in that case.

For those not yet using the beta version. I think this should do the trick.
Code:
var PercentRank(var* Data,int Period,var Value)
{
	int i,n;
	for(i=0,n=0; i<Period; i++)
		if(Data[i] <= Value) n++;
	return ((var)n)/Period;
}