Problems with ranking code

Hello,

I should appreciate it if someone would help me with the following simple code for ranking.

WatchList  = GetOption("FilterIncludeWatchlist");
List       = GetCategorySymbols(categoryWatchlist, WatchList);

if (Status("Stocknum") == 0 )
	{ 
	StaticVarRemove("Score*" );
	for (n = 0;(Symbol = StrExtract(List, n)) != ""; n++) 
		{ 
		SetForeign (Symbol);
		REMA    = Ref(EMA(Close, 8), -1);
		RROC    = ROC(Close, 6);
		RScore  = Max(0, IIf(Low <= REMA, 0, RROC));
		RestorePriceArrays();
		StaticVarSet ("Score" + Symbol, RScore);
		} 
	StaticVarGenerateRanks("Ranking","Score", 0, 1224); 
	} 
	
Symbol    = Name();
Score     = StaticVarGet ("Score" + Symbol); 
Ranking   = StaticVarGet ("RankingScore" + Symbol);

Filter = 1;
AddColumn(Score, "SymbolScore ", 1.2);
AddColumn(Ranking, "SymbolRanking", 1.2);

I can not get any result from it. Probably the error is quite obvious, but I am unable to find it.

Sin título
Thank you in advance for your help.

Best regards.

@jptrader, it is strange. I tried the code you posted, that seems correct, and my Exploration was showing results also in the SymbolScore and SymbolRanking columns.
The only situation where I got some "empty" values was when I used a database with a lot of inconsistent data (I mean where some symbols had different ranges of bars and multiple unaligned data holes). But I suppose that this is not your case.

Additional information that you can provide us: Are you using an EOD data or some mixed data / real-time data (and in such a case data provider/plugin)?
What is the Analysis periodicity you are using for the Exploration?
Which version of AmiBroker are you using?

Let's see if anyone else can reproduce your problem. And just to be sure, is the code posted EXACTLY the one that you used to generate the screenshot?

Simply output the BarCount and Interval in Explorer (see below code addition). Then you will have more information in front of you.

Also if you have enabled Pad&align of analysis settings - General tab then make sure that the symbol the data is aligned to has enough data itself. If that symbol has inappropriate Barcount then you may get empty results for sure.
Note: if Pad&align is enabled then the BarCount of the reference symbol is used/shown. I.e. if the reference symbol has just one bar of data but the WL symbols all have e.g. 1000 bars then Barcount will be 1 but not 1000.

WatchList  = GetOption("FilterIncludeWatchlist");
List       = GetCategorySymbols(categoryWatchlist, WatchList);

if (Status("Stocknum") == 0 )
	{ 
	StaticVarRemove("Score*" );
	for (n = 0;(Symbol = StrExtract(List, n)) != ""; n++) 
		{ 
		SetForeign (Symbol);
		REMA    = Ref(EMA(Close, 8), -1);
		RROC    = ROC(Close, 6);
		RScore  = Max(0, IIf(Low <= REMA, 0, RROC));
		RestorePriceArrays();
		StaticVarSet ("Score" + Symbol, RScore);
		} 
		StaticVarGenerateRanks("Ranking","Score", 0, 1224); 
	} 
	
Symbol    = Name();
Score     = StaticVarGet ("Score" + Symbol); 
Ranking   = StaticVarGet ("RankingScore" + Symbol);

Filter = 1;

AddTextColumn(Interval(2), "Interval", 1);
AddColumn(BarCount, "BarCount", 1);
AddColumn(Score, "SymbolScore ", 1.2);
AddColumn(Ranking, "SymbolRanking", 1.2);

But then even if index has just one bar the SymbolRanking column would show ranking output (e.g. all 1) and wouldn't be empty.


So I think the actual reason for your NULL output seems to be wrong Filter setting.
E.g. WL and some Market is chosen and "Match any" being checked.
Then both your columns may result in being empty.
So clear Filter and make sure only Watchlist is chosen. And check "Match all".

1 Like

beppe, fxshrat,

Thank you for your help!

fxshrat was right, I had a wrong Filter setting, I didn't notice that several Watchlist filters were selected.

Now the systems is working fine.

Best regards.