Watchlist ranking error

I am trying to rank a watchlist using StaticVarGenerateRanks. I know this has been extensively covered on the forum, but am having a small issue I can't resolve. I am using the following code, which works perfectly in most situations.

wlnum = GetOption( "FilterIncludeWatchlist" ); 
List = CategoryGetSymbols( categoryWatchlist, wlnum ) ; 

if ( Status("stocknum") == 0 ) 
    StaticVarRemove( "values*" ); 

    for ( n = 0; ( Symbol = StrExtract( List, n ) )  != "";  n++    ) 
        SetForeign ( symbol ); 
        values = Close * MA(Volume, 20);//GetFnData( "SharesOut" );
        StaticVarSet (  "values"  +  symbol, values ); 
        _TRACE( symbol ); 

    StaticVarGenerateRanks( "rank", "values", 0, 1224 ); 

symbol = Name(); 

MarketCap = StaticVarGet ( "values" +  symbol ); 
rank = StaticVarGet ( "rankvalues" +  symbol ); 

Filter = 1; 
AddColumn ( MarketCap, "MarketCap", 1.0 ); 
AddColumn ( rank, "rank", 1.0); 
SetSortColumns( 4 );

The exception is when running it on a historical date that precedes the first trading date for the first symbol in the watchlist. Evidently this relates to the line

if ( Status("stocknum") == 0 ) 

If the first symbol in the watchlist doesn't exist on the specified date no static variables or rankings are generated for the other symbols that do have data on that date.

Something tells me there must be an obvious/easy fix so that I can generate ranks for whichever symbols in the watchlist do have data for a specified date, but nothing I have tried has worked so I would appreciate any assistance.


Turn on DATA PADDING. It is required for ranking and mentioned hundreds of times on this forum. In fact having it off will generate warning in most recent versions of AB: Error 801 - it is advised to turn ON 'Pad and align to reference symbol'

1 Like

For Market Cap use:

values = GetFnData("SharesOut") * Close;

Also see getfndataforeign.

1 Like

Thanks Tomasz. Apologies, I don't recall coming across that before but will remember in future.


This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.