Exploration - how to exclude array items not meeting criteria

I am new to afl and I am using exploration code with the debugger to learn.
I would like some help with the following exploration....list those stocks having Close in the most recent 31 days which is (<= 52 week low + 10%) and that Close to be the most recent (lowest Close) in the 31 day period. Getting the low etc. is not a problem.
I need advice as to how to list only those array elements that meet the criteria in the exploration list.

You need to use the special Filter variable.


You can access elements with the Array Subscript
And arrays are of size BarCount and bars/elements aligned with the BarIndex() array.

Thank you. I was already using Filter but there must be something wrong with the variables / arrays I am using with Filter because my Filter does not work. Debugger is a great help so hopefully it will help solve my problem.

If you don't post the code, I don't think anyone can help you.
Other wise its just a guessing game.

Follow up to my original question.....

I have questions with the following incomplete code and would appreciate advice....

  1. Why does the Low52 array (from LLV) show differing values. Surely there can be only 1 Lowest Low in the 260 day period. Similarly for the CloseLow array.
  2. As LLVBars result is array how can I get the index of the Lowest Close in the 31 day period (also 260 day period) and the date on which that Low occurred. I really only want to include that array element in the Exploration if it is <= 52-week Low + 10%.

//Look for most recent Lowest Close within the last 31 days =< 52 week Low + 10%
//Code is incomplete

Liquidity = MA(C*V,21);
Filter = Liquidity >= 1000000;

LastX = LastValue(BarIndex()); //is number

// get the 52 week Low
Low52 = LLV(Low,260); //is array
//Add 10% to the 52 week Low
Low10 = Low52 + ((Low52 * 10) / 100); //is array
//Now get the Index of the 52 week Low
BarsSinceLow52 = LLVBars(Low,260); //is array
Low52X = LastX - BarsSinceLow52; //is array

CloseLow = LLV(Close,31); //is array
// get the lowest Close in the last 31 days
BarsSinceLowClose = LLVBars(Close,31); //is array
CloseLowX = LastX - BarsSinceLowClose; //is array


Firstly, do use Code tags </> when posting AFL code.

Not LLV() alone but thats how Array functions will generally work. There will be many values.
You have to look at it from a different view, ie. relative to that bar.

so LLV( C, 20); will return an array and the value at each bar is the lowest low value for a period of bars relative to that bar.

As for Question 2, ValueWhen() can be used, there is Lookup() as well that returns value at a specified DateTime.

@watchbird, the switch to array thinking can be a bit difficult/confusing.

  1. At each bar, the Low52 array will have a single value that is the LLV from the previous 260 bars/days. Now if you only want the "current" or "last" value, then you can use the "Lastvalue" function to get that value.

  2. I have found understanding Dates and Bar Numbers confusing to start. For this I suggest you use an Exploration to see the values change day by day to help you learn/understand.

In both 1 and 2, I expect an Exploration would be the best way for you to quickly see and learn what is going on in your code. As always, SEARCH is one of your best tools.

1 Like

Thank you snoopy & travick. For LLV I took the meaning in the AFL reference manual literally without properly considering the fact that the result is array. And Yes, array programming does take a bit to wrap one's head around particularly having always written code for non-array. The debugger and the associated Watch window are really helpful in checking "what is happening". I will continue with my exercise and hopefully reach the desired result.