Filter low volume/activity stocks

Hello everyone,

First I'd like to thank all the contributors to this forum for taking the time to read and reply to the other members.

I have searched the forum but haven't found any answer :frowning:

I would like to filter out from my script all the stocks that have low volume or low activity. Doing something like ma(v,100) > 300 to only get the

stocks that have a volume superior to 300 on average for the last 100 days is not enough.

I will try to explain, when I am on a 5min TF, there should be approximatively 8 * 12 = 96 bars for each day. (8 hours * 12 bars per hour on the 5min


Sometimes I will get across a chat that have only 1 or 2 5min bars quoted per day and those 1 or 2 bars have a volume > 300, so it doesn't get

excluded with the above filter.

If there was a way to filter thoses stocks that would be awesome, is there a way to check that there was at least 80 5min bars yesterday ?

Condition = numbers of bars of yesterday >= 80;

Maybe there is another way to accomplish that, if someone has an idea....Kindly appreci*ate it.


This thread has many posts on counting bars

You can append the bar condition to your Filter.

Thank you for you reply.

I almost got it, the following works but the dates are hard coded and didn't managed to get yesterday's date in the required format "YYYY-MM-DD".

StartDate = "2019-01-22";
EndDate = "2019-01-23";
bi = BarIndex();
StartBI = Lookup( bi, _DT( StartDate ));
EndBI = Lookup( bi, _DT( EndDate ));
barsbetween = EndBI-StartBI;

How can I get yesterday's date or the day before yesterday's date as a string like "YYYY-MM-DD" ?


Here you go. No Lookup required to get number of yesterday's bars.

/// @link
if ( Interval() != in5Minute && Status( "actionex" ) != actionExEditVerifyFormula )
    Error( "Set to 5-minute interval!" );
bi = BarIndex();
dn = DateNum();
newday = dn != Ref( dn, -1);
StartBI = ValueWhen(newday, bi, 2);
EndBI = ValueWhen(newday, bi, 1);
bars_yesterday = EndBI-StartBI;
lv_bars_yesterday = LastValue(bars_yesterday);
printf( "#Bars of LastValue(Yesterday): %g", lv_bars_yesterday);

Condition = bars_yesterday >= 80;

/// @link
Filter = Condition AND Status("lastbarinrange");
AddTextColumn(Interval(2), "Interval", 1);
Addcolumn(bars_yesterday, "#Bars", 1 );

BTW, please use code tags!
And if thread is solved you may hit solution button.


Thank you so much for the detailed code !!