How to count the number of tickers in a watchlist with condition?

Sec0=CategoryGetSymbols(categoryICB,0500);
_SECTION_BEGIN("ICB - 0500");
No=0;
iclose0=0;
ichange0=0;
for( i = 0; ( sym0 = StrExtract( Sec0,i ) ) != ""; i++ )
{
iclose0+=Foreign(sym0,"Close");
num0=1+StrCount(Sec0,",");
tb0=iclose0/num0;
ichange0+=ROC(Foreign(sym0,"Close"),1)/num0;
No++;
}
_SECTION_END();


I'm using the code above to calculate performance for each industries. This line only find out the number of tickers.
num0=1+StrCount(Sec0,",");
I’m trying to find a way to filter tickers with condition like:
cond0= V>=100000;
How to count number tickers with condition?
Thanks for your consideration!

.... num0=1+StrCount(Sec0,","); ...

Should'nt that num0.... code line be outside the for loop?
Just asking out aloud?

As for your question about filtering by volume, you would need to do add following code line somewhere appropriate.

if (Foreign(sym0, "Volume") >= 100000)

1 Like

@ThachCuong maybe something like this as a possible solution,

// select your WL in the Analysis window

wlnumber  = GetOption( "FilterIncludeWatchlist" );
watchlist = CategoryGetSymbols( categoryWatchlist, wlnumber );
SymbolCount = StrCount(watchlist, ",") + 1;

AboveTotal = 0;
VolumeThreshold = 7500000;

for( num = 0; ( symbol = StrExtract( watchlist, num ) ) != ""; num++ )
{

    SetForeign( symbol );

    Above = V > VolumeThreshold;
    AboveTotal += Above;

    RestorePriceArrays();

}

///  Exploration  ///
Filter = Status("LastBarInRange") AND Status( "stocknum" ) == 0;
SetOption("NoDefaultColumns",True);
AddColumn(DateTime(), "Date", formatDateTime);
AddColumn( AboveTotal, "# Symbols with Volume > " + VolumeThreshold + "", 1.0 );
AddColumn( SymbolCount, "Total # of Symbols in WL", 1.0);

Produces these calculations on today's Dow Jones Industrials
image

5 Likes

Thanks. You save my day.