Reputation: 4977
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?
I am using Amibroker v6.3
Upvotes: 3
Views: 1253
Reputation: 3668
Why do you think a for loop is slow and why would it not be suitable for Amibroker? Amibroker was lacking in this ability and was added so you have more control over setting arrays like you are doing in your code. The alternative was much more difficult from what I understand. That was before my time with amibroker though. But if you want something that looks nice try this.
BB_Initial = true; // Your initial BB array.
BB = IIF(BarsSince(Ref(AA, 8)) <= 8, false, BB_Initial);
But break this down into each step
BB_Initial = true; // Your initial BB array.
BB_Ref = Ref(AA, 8);
BB_BarsSince = BarsSince(BB_Ref);
BB_IIfCondition = BarsSince(BB_BarsSince) <= 8;
BB = IIf(BB_IIfCondition, false, BB_Initial);
That's five arrays to your two. But I can't really tell you how efficient Amibroker handles this syntax to what you are doing. Hope it helps.
Upvotes: 2