Duplicate: Explore problem about RANK function (StaticVarGenerateRanks)

I want to explore daily rank and weekly rank for some symbols in watchlist. I used stacticVarGenerateRanks and it works well in chart as indicator. But when I do exploration, the results are wield. There are different between exploration sequentially. All condition is same. Same symbol has data at one time(orange color marked), Some symbol’s result are different(blue color marked). And some symbol has no data.

I captured picture as followed. I also attached indicator and afl. Could someone please help me to check it out? I appreciate any advice. Thanks a lot!
21

AFL code is followed:

symlist = CategoryGetSymbols(categoryWatchlist,CategoryFind("Hopscotch",categoryWatchlist),0); 
StaticVarRemove( "Hps_*" ); 
P_wek=Param("Week_period",36,2,60,1);
p_day=Param("Day_period",18,3,210,1);
for ( i = 0; ( sym = StrExtract( symlist, i ) ) != ""; i++ ) 
 { 
     SetForeign( sym ); 
     valuetosortKD=RSI(p_day);
     TimeFrameSet(inWeekly);
     valuetosortKW=RSI(p_wek);
     TimeFrameRestore();
     StaticVarSet( "Hps_KD" + sym, valuetosortKD); 
     StaticVarSet("Hps_KW"+sym,TimeFrameExpand(valuetosortKW,inWeekly));
 } 

StaticVarGenerateRanks( "rank","Hps_KD",0,1224);  // normal rank mode
StaticVarGenerateRanks( "rank","Hps_KW",0,1224);
rankKD=100*(i-StaticVarGet( "rankHps_KD"+Name() ))/i;
rankKW=100*(i-StaticVarGet( "rankHps_KW"+Name() ))/i;

Plot(rankKD,"RKD",colorblue,styleline|stylethick);
Plot(rankKW,"RKW",26,styleline|stylethick);

Filter=1;
AddColumn(rankKD,"RKD",1.0);
AddColumn(rankKW,"RKW",1.0);

@freetone I tried a slightly different code than yours and it appears to work, and the ranking code was derived from an official knowledge base article

http://www.amibroker.com/kb/2014/11/26/handling-limit-orders-in-the-backtester/


P_wek = Param( "Week_period", 36, 2, 60, 1 );
p_day = Param( "Day_period", 18, 3, 210, 1 );

if( Status( "stocknum" ) == 0 ) // GENERATE RANKING WHEN WE ARE ON VERY FIRST SYMBOL
{
	StaticVarRemove( "Hps_*" );
	
    for( i = 0; ( sym = StrExtract( symlist, i ) ) != ""; i++ )
    {
        SetForeign( sym );
        
        valuetosortKD = RSI( p_day );
        TimeFrameSet( inWeekly );
        valuetosortKW = RSI( p_wek );
        
        TimeFrameRestore();

        StaticVarSet( "Hps_KD" + sym, valuetosortKD );
        StaticVarSet( "Hps_KW" + sym, TimeFrameExpand( valuetosortKW, inWeekly ) );
    }

    StaticVarGenerateRanks( "rank", "Hps_KD", 0, 1224 ); // normal rank mode
    StaticVarGenerateRanks( "rank", "Hps_KW", 0, 1224 );
}

rankKD = StaticVarGet( "rankHps_KD" + Name() );
rankKW = StaticVarGet( "rankHps_KW" + Name() );


Plot( rankKD, "RKD", colorblue, styleline | stylethick );
Plot( rankKW, "RKW", 26, styleline | stylethick );

Filter = 1;
AddColumn( rankKD, "RKD", 1.0 );
AddColumn( rankKW, "RKW", 1.0 );

image

1 Like

@freetone … and if it still does not work check this too!

Ranking sometimes not working (when you have holes in data)

Newcomers this one is for you: USE THE SEARCH BEFORE POSTING

This topic has been already discussed dozens of times. USE SEARCH. DO NOT START the same thing over and over. Problem is caused by holes in your data

1 Like