StaticVarGenreateRanks - Query on using it on historical data

I am using IBD style ranking generated by code below by running exploration. I am calling a function from a different file to display those rankings.

My query:
I'm i right in assuming that, If i run the ranking for a specific historical date and use it, I am getting the ranking on that particular day.

// https://forum.amibroker.com/t/how-to-imitate-ibd-relative-strength-percentile-ranking-of-stocks/6068/15
// Relative Strength ranking of stocks similar to Marketsmith India


// watchlist should contain all symbols included in the test
GetOption("PadAndAlignToReference");
wlnum = GetOption( "FilterIncludeWatchlist" );
List = CategoryGetSymbols( categoryWatchlist, wlnum ) ;
ListQty = StrCount(List, ",") + 1; 
// Determine the quantity of stocks to rank
StaticVarSet("UniListTotal", ListQty, True);
 
if( Status( "stocknum" ) == 0 )
{
	// Clear the static vars from last run
	StaticVarRemove( "RS_*" );
	StaticVarRemove("RSraw_*");
	StaticVarRemove("RankRSraw*_"); 

	// Generate the raw RS score for every stock and store in a static var
	for (n = 0; (Symbol = StrExtract(List, n)) != "";  n++) 
	{ 
		SetForeign (Symbol,0); 
		RSraw = 0;
		
		// relative strength IBD style
		ThreeMthRS  = 2*(C /Ref(C,-63));
		SixMthRS    = (C /Ref(C,-126));
		NineMthRS   = (C /Ref(C,-189));
		TwelveMthRS = (C /Ref(C,-252));
		RSraw = ThreeMthRS + SixMthRS + NineMthRS + TwelveMthRS; 
		
		RestorePriceArrays(); 
		StaticVarSet("RSraw_"  +  Symbol, RSraw); 
	} 

	// rank the stocks using this extremely useful function!
	StaticVarGenerateRanks("Rank", "RSraw_", 0, 1224); 

	for (n = 0; (Symbol = StrExtract(List, n))  != "";  n++) 
	{
		Rank  = StaticVarGet ("RankRSraw_" +  Symbol); 
		RSpctile = 100 - 100*Rank/ListQty;
		StaticVarSet("RS_" + Symbol, RSpctile, True);
	
	}

}

Filter = 1;
Rank  = StaticVarGet ("RS_" +  Name()); 

// exploration code for verification
AddColumn(Close, "Close", 1.2);
AddColumn(Volume, "Volume", 1.0);
AddColumn(Rank, "Rank",1);
SetSortColumns(-5);

// Calling RS ranking generated from IBD_RS_Ranking.afl
function GetRS(Symbol)
{
	// Retrieve relative strength static var
	return StaticVarGet ( "RS_" +  Symbol ); 
}
AddColumn( GetRS(Name()), "RS Rating", 1 );

Ok, i realized i can test this and tested my exploration first on a random date followed by running the ranks on the same date(IBD_RS_Ranking.afl) to see what happens.

Using Excel Vlookup, I found that it is unnecessary to run the ranks before explore, the ranks shown in exploration are same as ranks generated by IBD_RS_Ranking.afl itself.

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