|SYNTAX||StaticVarGenarateRanks( "outputprefix", "inputprefix", topranks, tiemode )|
|FUNCTION|| The function implements general-purpose multiple symbol bar-by-bar ranking.
StaticVarGenarateRanks( "outputprefix", "inputprefix", topranks, tiemode )
"inputprefix" is a prefix that defines names of static variables that will be used as input for ranking. AmiBroker will search for all static variables that begin with that prefix and assume that remaining part of the variable name is a stock symbol. Say you want to rank stocks by ROC (rate of change). All you need to do is to store values into static variables.
Let us say that we will use static variable names like "ValuesToSortAPPL", "ValuesToSortMSFT", and so on.
To fill input static variables you can use this loop:
Now you are ready to perform sorting/ranking. There are two modes, normal ranking mode and Top/Bottom Rank mode.
Normal ranking mode is performed when toprank argument is set to zero.
StaticVarGenerateRanks( "rank", "ValuesToSort", 0, 1224 );
In this case StaticVarGenerateRanks call would generate set of static variables starting with prefix defined by 2nd argument each variable holding the rank of particular symbol, so in this case
RankValuesToSortMSFT will hold ranking of MSFT
Note that in AmiBroker rank count start from ONE.
Third argument (topranks) is zero in normal ranking mode
Fourth argument (tiemode) defines how ties are ranked. Supported modes are 1234 and 1224. In 1224 mode ties are numbered with equal rank.
Top/bottom ranking mode (that generates top/bottom ranking tables that hold indexes to top ranking values. When topranks > 0 top ranked values are used, when topranks < 0 then bottom ranked values are used. The values are stored in variables that have format of: OutputprefixInputprefixN where N is a number 1, 2, 3 representing top/bottom ranks. Let us assume that OutputPrefix parameter is "Top" and Inputprefix parameter is ROC. In such case variable TopROC1 would hold the index of top rated value. TopROC2 would hold second top rated value, and so on.
StaticVarGenerateRanks function uses rank numbering that starts from ONE.
In top ranking mode StaticVarGenerateRanks will also prepare static variable that contains comma separated list of variable names that can be used to find out which index refers to which symbol. So if TopROC1 holds 1 you would lookup first substring in TopROCSymbols variable to find out what variable (symbol) ranked at the top. Additionally StaticVarGetRankedSymbols gives easy-to-use method to retrieve comma separated list of ranked symbols for particular datetime.
|SEE ALSO||StaticVarGetRankedSymbols() function|
The StaticVarGenerateRanks function is used in the following formulas in AFL on-line library:
See updated/extended version on-line.