Fill past values of array using array method

I would like to assign past 8 bars of array BB with false value when current bar of array AA is true. This is the code I wrote;

for( i = 8; i < BarCount; i++) 
{
	if (AA[i] == True)
	{
		BB[i] = False;
		BB[i-1] = False;
		BB[i-2] = False;
		BB[i-3] = False;
		BB[i-4] = False;
		BB[i-5] = False;
		BB[i-6] = False;
		BB[i-7] = False;
        BB[i-8] = False;
	}
}

The code works fine but it uses the loop approach. Loop approach is slow and is not suitable for Amibroker. How can this AFL code using loop be converted into a faster, more elegant array approach?

Sure, you can do this.
But you will look into the future! I hope you are aware of this.

// e.g.:
AA = Cross(C, MA(C,200));
BB = 1;

BB = Nz(Reverse( BarsSince(Reverse(AA)) > 8), BB);

/*
// if BB isn't a scalar:
BB = ... ;
BB = IIF(IsNull(BB), Reverse( BarsSince(Reverse(AA)) > 8), BB);
// If your BB looks back, you need to adjust the upper line sometimes  
*/
1 Like