I am interested in performing a ranking based on relative strength as a high level screener and taking the top X performers. Then use those as my list of tickers to perform subsequent analysis on.
I found this example code below from this post which is very similar, to what I was thinking of.
However, GetOption( "FilterIncludeWatchlist" );
will only take a single watchlist in the Filter settings. I was actually interested in using multiple watchlists as my input. I thought maybe using the watchlist names and adding the resulting symbol Lists together would be a way around that. I attempted to do that with one watch list name and it does not seem to work correctly.
Any help on how to run a ranking on multiple watchlits would be appreciated.
// ################ Ranking Exploration #################
// watchlist should contain all symbols included in the test
//wlnum = GetOption( "FilterIncludeWatchlist" );
wlname = "S&P 500";
wlnum = CategoryFind( wlname, categoryWatchlist );
List = CategoryGetSymbols( categoryWatchlist, wlnum ) ;
if( Status( "stocknum" ) == 0 )
{
// cleanup variables created in previous runs (if any)
StaticVarRemove( "rank*" );
StaticVarRemove( "values*" );
categoryList = ",";
for( n = 0; ( Symbol = StrExtract( List, n ) ) != ""; n++ )
{
SetForeign( symbol );
// write our ranking criteria to a variable
// in this example we will use 10-bar rate-of-change
values = ROC(C,10);
RestorePriceArrays();
// write ranked values to a static variable
StaticVarSet( "values_" + symbol, values );
}
// generate ranks
StaticVarGenerateRanks( "rank", "values_", 0, 1224 );
}
symbol = Name();
values = StaticVarGet( "values_" + symbol );
rank = StaticVarGet( "rankvalues_" + symbol );
// exploration code for verification
AddColumn( values, "ROC" );
AddColumn( rank, "Rank" );
Filter = rank <= 6;