Mike and TradeOptions
AFAIK,
PercentRank is strictly an inter-stock function. i.e. It will compare and rank data of the same stock over different candles. There is another sister function named
Percentile that kinda works in tandem with
PercentRank
AddRankColumn is for adding rank to exploration and is just means to get amibroker to provide sneak peak on how it does exploration sorting when
SetSortColumn is used
StaticVarGenerateRanks is primarily an intra-stock function and it makes of static variables to get it right. Also, if you are using this function while dealing with fast filling data feed over reasonably large data set, this function keeps getting thread-interrupted and you have to deal with threading and semaphore managements.
There is no reliable self-sufficient example that I have come across on the
StaticVarGenerateRanks function. Default example provided in the amibroker help neatly avoids all the real trading implementation problems ...
Also, if you this function, values of static variables will remain set even after you shutdown and restart Amibroker!. They remain set even if you shutdown and restart your computer. Therefore, you have to be very careful to prevent ending up with stale out-dated rank OR {EMPTY} value staring back at you.
Code:
/////////////////////////////////
// Example 1. code for normal ranking mode
// (everything done is done in one pass, can be used in indicator):
/////////////////////////////////
symlist = "C,CAT,DD,GE,IBM,INTC,MSFT";
// delete static variables - DO NOT forget the asterisk (wildcard) at the end
StaticVarRemove( "ValuesToSort*" );
// fill input static arrays
for ( i = 0; ( sym = StrExtract( symlist, i ) ) != ""; i++ )
{
SetForeign( sym );
Value = ROC( C, 10 );
RestorePriceArrays();
StaticVarSet( "ValuesToSort" + sym, Value );
}
// perform ranking
StaticVarGenerateRanks( "rank", "ValuesToSort", 0, 1224 ); // normal rank mode
// read ranking
for ( i = 0; ( sym = StrExtract( symlist, i ) ) != ""; i++ )
{
Plot( StaticVarGet( "RankValuesToSort" + sym ), sym, colorCustom10 + i );
}