Optimizing the AFL code of LLV

Hi!
One part of my exploration operates on LLV functions. I use it to find tickers that were traded under 1$ in the history (I check from the beginning to the current bar). I use this code:

bi = Barindex();
	qfdb = Status( "quickaflfirstdatabar" );
	qbi = qfdb + bi;
if1usd=IIf(LLV(L,qbi)<1.00, 1, 0); //check if it was traded under 1$

The problem is the LLV function works extremaly slowly. In Code Check and Profile it shows 4-7 seconds for one call of LLV so scanning around 8000 stocks takes really long.
Is there any way to optimize this code (or change it)? I found that in other cases LLVs (or HHV) functions work slowly, too. Any ideas how to replace LLV (or HHV) to make it working fast?
Thanks for help and suggestions.

@piotrd passing qbi (that is an ARRAY derived from BarIndex()) as "periods" to your LLV function you are actually invoking it with a variable period. Is that done on purpose?

Moreover, I do not understand why are you using the value of Status( "quickaflfirstdatabar" );. What do you mean by "I check from the beginning to the current bar"? What is the "current bar" for you in exploration?

I suggest explaining your purpose further. Even better, use the explorations functions to check the values of all your variables and arrays to understand your formula's implications and results properly.
To simplify your debugging sessions, I suggest that you initially filter using only the "Current Symbol" applied to a ticker that you know has quoted below $ 1 in the past.

1 Like

Maybe you are interested in Lowest function
regards

OMG... it was so simple just to use Lowest... yes, it works much faster.

@beppe:
The idea to use

Status( "quickaflfirstdatabar" ) etc.

wasn't mine - I took it from this forum. I did it because without this solution BarIndex shows different values depending on zoom in/out of the chart and I wanted to include in exploration the whole dataset.
Now I wonder if zoom in/out causes different values for BarIndex for chart only or maybe it has some influence on exploration. If for chart only, then "Status( "quickaflfirstdatabar" ) and qbi" is actually not needed.

I divided my code into two different formulas. I decided to find tickers under 1USD separately, i.e. create the watchlist of the results of comapnies that were traded in the history under 1USD and then, using other formula, make proper exploration.
However in this case, there is one problem:

aBeginPrice=1.00;
under1usd=IIf(Lowest(L)<aBeginPrice, 1, 0); 
Filter=under1usd;

It shows the companies that were traded under 1usd. The exploration is sufficent to be done on Weekly interval (8000 tickers, 2 years intraday data as a source). The exploration takes 2 minutes, but it stops at 100% and waits for very long time. If I click Stop, then I can see the results and they look OK. Can you give me a hint why it stops at 100% and not finishing the exploration for very long time ?

@piotr, my question was mainly related to the fact that in your code, you summed qbi = qfdb + bi;. The result of this expression is an ARRAY, and as such your call to LLV () was probably doing something other than what is normally expected.

From the manual:

"quickaflfirstdatabar", "quickafllastdatabar" - This feature is for internal use only. These are bar indexes of actual underlying compressed quotation array that make up AFL's array[ 0 ] and array[ BarCount - 1]

This feature is still marked for internal use only. This means that, in general, it is wise not to use (the internals may change in the future). I looked at some past threads where it was used, buy maybe @Tomasz could provide us more info about the cases where it is OK to use it.

Usually, in my code, when I want to be sure that all the bars are used, I write:

SetBarsRequired(sbrAll, sbrAll); //  this turns OFF quickAFL

The documentation and this KB article explain well when is needed, when it is redundant and when use it to DECREASE the numbers of bars required for a formula specifically.

Re the last issue, unfortunately, I cannot help at all since I do have any huge intraday (what time unit?) database (how big is the data on disk?).

Did you ever waited enough to see if it eventually terminates?

Please, see this previous thread, where there are some suggestions, even if it is about a different "stuck in progress" problem. If it is of no help, it is better to ask to @Tomasz directly.

"quickaflfirstdatabar" feature will not disappear or stop working.
The thing about "quickaflfirstdatabar" is that in properly written code you should not really care about such data. It should be irrelevant. The code that must use it is doing something wrong.

And it is not good approach to turn off QuickAFL in all formulas. QuickAFL gives HUGE savings when it comes to execution time. Turning it off is equivalent to riding Bugatti Veyron on first gear only.

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