Code snippet is not really helpful bcos there's no point going through your code Line-by-line and trying to figure out what Logic you intended to apply.
Unless there is a syntax error.
Just saying output is not as expected is not useful in any way, post the output and what should be in its place.
If you are posting snippets, make sure its still executable code, not one that will throw half-a-dozen errors.
Even if I took time out to fix them, how do I know what's the right output?
Read here and share more details, are you sure the Required bars are set right(if needed) and quickafl is not actively doing what its supposed to do?
This can easily cause such symptoms.
Maybe you just start with describing in plain English what you want to rank, what is the "equation" you would like to use and what is your "expected" result.
//TimeFrameSet(inWeekly);
startdate = DateTime();
enddate = DateTime();
scoreBackdays = param("Scoring lookback days",5,0,50,1);
startdate = ParamDate( "Start date (working day)", "2018-08-25");
bench = ParamStr( "Bench", "-EGX30" );
xxx=0;
fv=ValueWhen(DateNum() == startdate, BarIndex(), n = 1);
fvb=LastValue(fv);
fc = C;
Xo = fc[fvb];
AddColumn(C,"C");
AddColumn(fvb,"fv");
Filter =fc;
fx = Foreign( bench, "C" );
Yo =fx[fvb];
AddColumn(Yo,"C bench");
nrsArray=0;
nrsArrayBench=0;
nrsDiff=0;
for(i=fvb;i<BarCount;i++)
{
nrsArray[i]=(C[i]/Xo)*100;
}
for(i=fvb;i<BarCount;i++)
{
nrsArrayBench[i]=(fx[i]/Yo)*100;
nrsDiff[i]=nrsArray[i]-nrsArrayBench[i];
}
AddColumn(nrsArray,"nrs");
Mainlistnum = GetOption( "FilterIncludeWatchlist" ); //ok...probably about identify and getting the number of stocks in universe
Mainlist = CategoryGetSymbols( categoryWatchlist,Mainlistnum); //ok..probably about identify and getting list of stocks in universe
StaticVarRemove( "ValuesToSort*" );
StaticVarRemove( "rankValuesToSort*" );
// Fill input value (for ranking) into Static arrays
for ( i = 0; ( sym = StrExtract( Mainlist, i ) ) != ""; i++ )
{
cFor= Foreign(sym, "C" );
fc = cFor;
Xo = fc[fvb];
for(j=fvb;j<BarCount;j++)
{
nrsArray[j]=(cFor[j]/Xo)*100;
}
if(sym==Name())
AddColumn(nrsArray,"NRSARRAAY");
Value = nrsArray;
StaticVarSet( "ValuesToSort" + sym, Value);
}
// Perform Ranking
StaticVarGenerateRanks( "rank", "ValuesToSort",0,1234 ); // normal ranking
RestorePriceArrays();
todayrank = StaticVarGet("rankValuesToSort" + Name());
AddColumn(todayrank,"rank");
YesterdayRank = Ref(todayrank,-1);
BeforeYesterdayRank = Ref(todayrank,-2);
AddColumn(YesterdayRank,"YesterdayRank");
AddColumn(BeforeYesterdayRank,"BeforeYesterdayRank");
and here is a snippet of the explore, i rank based on the blue column which is the nrsAraay and the red on is the ranking
and as you can see there are a lot of stocks were there is no ranking even though there is values for that stock