Loop error in last bar

Hi everyone,

I have a loop to identify opening range breakouts here:


firstBarOpen = ValueWhen(MinutesSinceOpen == 0, Open);
firstBarHigh = ValueWhen(MinutesSinceOpen == 0, High);
firstBarLow = ValueWhen(MinutesSinceOpen == 0, Low);
firstBarClose = ValueWhen(MinutesSinceOpen == 0, Close);

for( i = 0; i < BarCount-1; i++ )
{

	if ( firstBarOpen[i] > firstBarClose[i] )
	{
		possibleLong[i] = 0;
		possibleShort[i] = 1;
	}
	
	if ( firstBarClose[i] > firstBarOpen[i] )
	{
		possibleLong[i] = 1;
		possibleShort[i] = 0;
	} 
	
	if ( High[i] > firstBarHigh[i] )
	{
		highBreak[i] = 1;
	}
	if ( Low[i] < firstBarLow[i] )
	{
		lowBreak[i] = 1;
	}
}

However, I'm seeing some behavior I can't explain on the latest bar. I've set the possible long to 1 if the first bar close is great than the first bar open. However this value doesn't seem to calculate on the lastest bar. For instance with AAP on 4/8 I've used the bar replay to look at 9:30 stepping to 9:35 then 9:40 and for each the last bar in time still seems to have the possible long and possible short equal to zero.

I'm probably coding this wrong, can someone help educate me?

Thanks so much in advance!

Your loop iterates till second to last bar but not till last bar.
Remove minus one in loop statement.

Ah gosh! Thanks!

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