// Parametrize as needed
lastRankAccepted = 10;
ROCPeriod = 5;
// Check the Pad&Align settings since this examples uses Foreign()
// TJ: "ANY kind of ranking REQUIRES data to be aligned (i.e. without holes)"
// Code adapted from: http://www.amibroker.com/kb/2016/01/
// watchlist should contain all symbols included in the test
wlnum = GetOption( "FilterIncludeWatchlist" );
List = CategoryGetSymbols( categoryWatchlist, wlnum ) ;
if( Status( "stocknum" ) == 0 )
{
// cleanup variables created in previous runs (if any)
StaticVarRemove( "rank*" );
StaticVarRemove( "values*" );
for( n = 0; ( Symbol = StrExtract( List, n ) ) != ""; n++ )
{
SetForeign( symbol );
// write our ranking criteria to a variable
// in this example we will use ROCperiod-bar rate-of-change
values = Roc( Close, ROCPeriod );
RestorePriceArrays();
// write ranked values to a static variable
StaticVarSet( "values_" + symbol, values );
}
// The "tie" mode (4th param) defines how ties are ranked. 1234 means that ties are NOT numbered with equal rank.
StaticVarGenerateRanks( "rank", "values_", 0, 1234 );
}
// Exploration
rank = StaticVarGet( "rankvalues_" + Name() );
Filter = rank <= lastRankAccepted;
AddTextColumn( FullName(), "Description", 1, colorDefault, colorDefault, 200 );
AddColumn( Close, "Close" );
AddColumn( ROC( C, ROCPeriod ), "ROC" );
AddColumn( rank, "Rank", 1 );
if( Status( "action" ) == actionExplore )
SetSortColumns( -2, 6 );