Limit number of bars to AFL

I'm running a scanner using exploration and the requirement is to scan @ every 2 sec in a 1 min timeframe.
I used _trace() function to check how many bars are used by AFL and found that it's using around 35, 000.

then I turned on Quick AFL, now the bar used by AFL is reduced to 11,000.

I want to restrict the number of bars used to 500.

I want AFL to be executed just on the current intraday day.

Note: there is no formula used in AFL that required the previous day's bars.


Please read this document about QuickAFL:

1 Like

Hi Tomasz,

Thanks for your quick reply.
I have gone through this link earlier and now I have better clarity.

I used check and profile profile tool and found the below number .

29467 data bars used during this check. Total execution time: 0.1817701 sec.
Approximately 10794 past and ALL future quotes are needed to calculate the formula properly

and the exactly same numbers of bar being used during exploration when Quick AFL is turned ON.

I'm just curious to know how 10794 past bar is being used even if I'm not using any formula which may require past bar in my understating like moving average etc. In reality I don't need any past bar to generate Buy or Sell signal for current intraday.

Do we have any feature like where we can just provide current intraday bars as input to AFL?
This will solve my issue and hence I'm able to reduce my running time of AFL.

What I have done so far.

I have changed data base settings to just 500 bar then I found that
my data provide backfill around 3months of history data which is around 35K 1 min bars and if I'm using any figure less than the above number for intraday bar , actually not getting lasted day chart.

so from database setting point of view I have to keep this around 35K at least to get the latest intraday candle.

If it was python program then I just took the current day data frame(using data frame filter) and used as input to my formula but for amibroker I'm not aware how to achieve this.

Please help me. :pray:

See here:

Hi Tomasz,

Thanks for the help.
Solved this problem using "SetRequiredBar" method.

Steps I followed.

  1. set exploration ON for every 2 sec.
  2. paste blindly "SetBarsRequired(400, 0)" where ever I used loop or in built formula.
  3. at some point it started showing bar count less than 600
  4. then did reverse engineering, which place cause bar count sudden drop.
  5. Removed from the other un-necessary places.


Hi Milosz,

Thanks for your help.
I have gone through your answer and also found that setRequiredBar should be placed below the formula to override the previous value of the past and future bar.

the SetRequired bar is able to reduce the number of past and future candles used.

But I observed AFL is not working properly when stop loss hit in current candle (like a cross over happen, high or low break)

I have used
setRequiredBar(400, 0); => this is not working (unbale to get exit )
setRequiredBar(400, sbrAll);=> this is also not working, (sometime works, sometimes does not)

When I remove the setRequiredBar then everything works as expected but takes 5X more times in execution.

Please help here. my AFL does require more than 300 past bars to work properly, for the future bars I'm not sure.

Is there any other way where I can just instruct amibroker to consider only today's intraday bars?

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