I have code that ranks all the symbols in my DB according to volume for each day. It looks like everything is working fine, but when I look at the result list, there are always some positions in the ranking that are missing and I just can't figure out why.
Here is the code:
List = CategoryGetSymbols( categoryAll, 0 ) ;
symbol = "";
if( Status( "stocknum" ) == 0 )
{
StaticVarRemove( "rank*" );
StaticVarRemove( "values*" );
for( n = 0; ( symbol = StrExtract( List, n ) ) != ""; n++ ) {
SetForeign( symbol );
value = MA( Ref(Volume, -1), 20 );
RestorePriceArrays();
StaticVarSet( "value" + symbol, value ); // write ranked values to a static variable
}
StaticVarGenerateRanks( "rank", "value", 0, 1224 );
}
symbol = Name();
values = StaticVarGet( "value" + symbol );
rank = StaticVarGet( "rank" + "value" + symbol );
AddColumn( values, "Value" );
AddColumn( rank, "rank" );
Filter = rank <= 10000;
if( Status( "Action" ) == actionExplore ) SetSortColumns( 4, 2 );
And here is a screenshot of the exploration output. As you can see, lots of positions in the list are missing, for example #1 to #4, #14 etc. Can anyone help me understand why some tickers appear missing?
@Muzzle, in any case, please, also fix your code as suggested by @TrendSurfer to clear the (previously used) static variables.
In your case, repeating the exploration using "all symbols" will simply overwrite previous static variables (never deallocating them - a waste of memory).
In other situations, doing the same exploration using different watchlists, without properly clearing the static vars that you plan to reuse, could lead to some weird results.