How to force decrease "SetBarsRequired" in "actionIndicator" after increase?

Hello Tomasz,

Could you answer a little question?

What`s the way to tell Ami force hot dynamic decrease "SetBarsRequired" in "actionIndicator" by pure AFL without manual new insert/change Afl (first execution) formula after Ami stored inside itself more "SetBarsRequired"?

And what is technically (internal) "first execution" of afl in "actionIndicator"?

Hot increase working but hot decrease ignored.
Is it a protection from guys shooting off their eggs themself?


I don't know what is "hot dynamic" increase/decrease according to you, but you can definitely decrease number of bars that are used during code executing, by placing SetBarsRequired() at the end (not at the beginning or somewhere else) of the formula. Read here:

SetBarsRequired() gives you also ability to DECREASE the requirements of formula. This is done by placing SetBarsRequired at the END of your formula, as any call to SetBarsRequired effectively overwrites previously calculated estimate.

1 Like

Thanks for you answer, Milosz.

You know, the stars have formed so that I know Ami not worse than you maybe.
Of course I know about SetBarsRequired at the end of code.

But you didn`t understand my question.
Try to execute very simple example in actionIndicator,
include "Display chart timing (advanced)", change "param Bars" and you will see that.

Bars= Param("Bars", 0, 0, 10);
SetBarsRequired(Bars, Bars);


As written in KB article about QuickAFL, the "reset" of required bars is done when you insert a new formula into chart or when formula changes. It is not reset when you change the parameters. It may only increase requirements if required periods for parameters are larger. That is safety measure.

@Tomasz - Is there no manual manual way for the user to trigger a reset of QuickAfl directly from the AFL code? This would save from having to run a scan(s) just to backfill data into static variables.

"Manual" .... "from the AFL code" ?

Either something is manual or something can be done from code (not manually).

And I already answered that in QuickAFL article and in previous response (in bold text).

Ok - by manual (sorry for the double word), I meant can we trigger a reset of QuickAFL via the AFL code (for instance through ParamTrigger). I take it that it is not possible. I see that it can be done by changing the formula and saving it through the editor, but that is not really that useful.

It would be very helpful to have a way to reset QuickAFL without having to resort to editing the code or restarting AmiBroker/closing/reopening the chart.

Since posting my original question, I found this comment in the feedback center which explains the issue more succinctly

Why don't you understand what I wrote. IT IS DONE FOR PURPOSE. It is safety measure. Prevents users from shooting themselves in foot. And it won't change, because (as everything in AmiBroker) is deliberate design decision based on 20 years of experience in program design and 20 years spent answering support so I know precisely what consequences of each decision are. And consequence would be hearing 100+times daily that "indicators are calculated wrong" just because user shoot himself in the foot and forcefully decreased number of bars so much that there is not enough data to calculate precisely.

Because of AmiBroker's versatility, and the fact that it relies on code inputted from the users, there are already many, many ways that users can shoot themselves in the foot. I imagine there are those who complain that their charts are slow after using SetBarsRequired (-2, -2) and don't understand that they can't return the chart to its default.

Not having this capability forces the user to use scans (which necessitates that at least one other file needs to be created/managed; two files if you use batch for this) - which does work, but is a clunky solution rather than just permitting the user to return a chart to its default QuickAFL settings through a function or other means.