Look for past Areas-candles AFL

@Optimvs, in addition to the suggestion by @awilson, this past thread will help to understand better how AmiBroker treats scalar and arrays and what happens when you assign a scalar to an array (Buy is an array).

Maybe in your loop you should use:

BUYCondEntry7[j] = .... 

or

if (BUYCondEntry7[j]) 
    ....

But probably it is better to use array operations as:

BUYCondEntry7 = BUYCondZone1 AND BUYCondZone2 AND BUYCondZone3 AND BUYCondZone4;

And then use some extra code/condition to apply it only when it is TRUE in your desired bars range/ areas (as said it is not clear to me why you are using a loop for this).

As a debugging / learning AFL tool I strongly suggest you to use some Exploration code.

As a minimum, add to your formula these lines:

Filter = 1;
AddColumn( BUYCondEntry7, "BUYCondEntry7", 1 );
AddColumn(  Buy, "Buy", 1 );

And execute the Analysis on a single ticker for some 300 recent bars.

As a beginner, I will probably use a more verbose exploration like this:

function nil( a )
{
    return ( IIf( a, a, Null ) );
}
Filter = 1;
AddColumn( C, "Close" );
AddColumn( O, "Open" );
AddColumn( H, "High" );
AddColumn( L, "Low" );
AddColumn( V, "Volume", 1 );
AddColumn( Nil( BUYCondZone1 ), "C>O", 1 );
AddColumn( Nil( BUYCondZone2 ), "H-L<=MaxSL", 1 );
AddColumn( Nil( BUYCondZone3 ), "H-C<C-O", 1 );
AddColumn( Nil( BUYCondZone4 ), "V>VMinZ", 1 );

//BUY Entry Conditions
AddColumn( Nil( BUYCondEntry1 ), "L<=HHZ", 1 );
AddColumn( Nil( BUYCondEntry2 ), "L>=LHZ", 1 );
AddColumn( Nil( BUYCondEntry3 ), "V<VolMinEn", 1 );
AddColumn( Nil( BUYCondEntry4 ), "tn>=In.AND tn<=End", 1 );
AddColumn( Nil( BUYCondEntry5 ), "MA_21>Ref(MA_21,21)", 1 );
AddColumn( Nil( BUYCondEntry6 ), "MA_21>MA_80", 1 );
AddColumn( Nil( BUYCondEntry7 ), "COND 7", 1 );
AddColumn( Nil( Buy ), "Buy", 1 );
AddColumn( Nil( Sell ), "Sell", 1 );
SetSortColumns( -2 );

(And if needed will also add some other used arrays like tn, MA_21, MA_80, etc.)

1 Like