I downloaded some code from the KB and when I use it to explore a watchlist amibroker closes
code below:
// 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*" );
categoryList = ",";
for( n = 0; ( Symbol = StrExtract( List, n ) ) != ""; n++ )
{
SetForeign( symbol );
// use sectors for ranking
category = GicsID();
// add sector to the list
if( ! StrFind( categoryList, "," + category + "," ) ) categoryList += NumToStr( category, 1, 0 ) + ",";
// write our ranking criteria to a variable
// in this example we will use 10-bar rate-of-change
values = Roc( Close, 10 );
RestorePriceArrays();
// write ranked values to a static variable
StaticVarSet( "values" + category + "_" + symbol, values );
}
// generate separate ranks for each category from the list
for( i = 1; ( category = StrExtract( categoryList, i ) ) != ""; i++ )
{
StaticVarGenerateRanks( "rank", "values" + category + "_", 0, 1224 );
}
}
category = sectorID();
symbol = Name();
m = Month();
values = StaticVarGet( "values" + category + "_" + symbol );
rank = StaticVarGet( "rank" + "values" + category + "_" + symbol );
// exploration code for verification
AddColumn( values, "values" );
AddColumn( rank, "rank" );
AddTextColumn( SectorID( 1 ), "Sector" );
AddColumn( SectorID(), "Sector No", 1 );
Filter = rank <= 2;
if( Status( "Action" ) == actionExplore ) SetSortColumns( 2, 5, 4 );
// sample backtesting rules
SetBacktestMode( backtestRotational );
score = IIf( rank <= 2, values, 0 );
// switch symbols at the beginning of the month only
PositionScore = IIf( m != Ref( m, -1 ), score, scoreNoRotate );
SetPositionSize( 1, spsPercentOfEquity );