How do I limit the number of Trades per day (in Exploration or Scanning)


I want to control the number of trades which can be executed during a live trading session. I normally use scan option and run a watchlist which has multiple stocks.

I want the trade limit in exploration / scanning (NOT BACKTESTING).

Not sure what error I am committing, could someone highlight please.

I have listed below my code.

(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));


LE=C>E1 AND E1>E2;



for (i=1 ;i<BarCount;i++)

if (newday[i]==1)

if (LE[i]==1 AND bflag==0  AND TradeNo<=3)

if (LX[i]==1 AND BFLAG==1)


Please help.

Thanks & Regards

If you entered 'limit trades per day amibroker' into Google the FIRST result would be

Really use google the answers are already there in kb

The difference between exploration or backtest is practically zero. If you just add two lines to the code from Knowledge Base

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

you will get exploration-ready formula.


Hello Tomasz,

Thanks for your reply.

I did see this link before, but this is not what i am looking for.

This link restricts the number of trade per script rather than the total number of trades per day.

My requirement is i have a watchlist of 20 scripts and these will be continuously scanned at a specific intervals. When the signal is generated, the system fires an order. However, the total number of signals to be generated for 20 scripts per day should be restriced (say 10).

That seems to be a challenge for me. Thats why i used static variable, but that too is not giving me desired output.'

Thanks & Regards

Why would you want to start from 1, can't you count the number of Bars Since new day and start from there?

Read how Exploration Loads an Array, and if QuickAFL is on or have you set the bars?
You don't even mention how the bars are "set" in the Range, is From-To or by X recent bars?
Have you defined SetBarsRequired() ?

simply running I=1 to BarCount implies you've not got the array part.

  1. You don't even mention whether you are trying to achieve this as intraday trades or not. I've had to read few times, and its still not clear.
    It is not even clear what TimeFrame you are running on.
if (newday[i]==1)

By doing this, you have reset variable every bar in new day, how do you expect state information to be stored.
Atleast i'm confused.
The code will fire every buy signal.

And can anyone beat this
bflag then somewhere
BFlag and then somewhere

i've had enough already, I'm moving onto another thread.

Hi Travick,

Thanks for your reply, and apologies for not being clear. I am relatively new to Amibroker, and this is my first thread in the forum, so I was not sure what all information to provide. But I definitely realize that the information which you need are critical for explaining.

This is a intraday strategy, hence I am resetting the day every time, and the Timeframe which I am using is 5 Minute.

Like I said, I am relatively new, I am not aware of SetBarsRequired and QuickAFL which I will explore now.

Nevertheless, even if the AFL runs every time (I know its redundant) from 1 to barcount, it should still work isint it? There must be a reason for not working and I am trying to figure it out.

Also, regarding bflag / BFlag / BFLAG.. I am not an IT coder, my background is Finance, and I am currently learning to code.. so I really don't know good coding procedure. Thanks for pointing it out. Nevertheless I read the capitalization of variables should not affect the result.

Thanks & Regards

Many on the forum will be eager to help, provided they see some effort and that's the case here.

I won't type a long post, but all i'll tell you is to go through the various threads and manual and you will realize how general code is written.
There is a correct approach to everything, wrong approach will not be solved by correct code.

Also, regarding bflag / BFlag / BFLAG.. I am not an IT coder

When you fill your name or address etc on any form, you do maintain consistency right? its not about profession.
John is John everywhere, not jOhn of JoHN or JoHn or johN as one wishes, same applies everywhere.

Finally, just read through the KB and AFL, you will see that each bar is computed individually, so a plain check like this will result in erroneous results.

if (newday[i]==1)

Do some research, then post code and you'll get assistance for sure.

Thread has been closed because it was abused / hijacked and offending content (personal attacks on other forum members using very offending language) was posted. Offending content and replies have been deleted. Person who violated forum rules has been removed from forum. Forum rules must be followed.