Consider the classic Amibroker method to rank stocks. In particular this one is based on three criteria.
The final rank is a weighted combination of the ranks of the three criteria.
My question is: how can i modify the final array "rank" so that it will have integers starting from 1?
I need this because in my buy condition i want introduce "rank <=10", that is i want not buy more then 10 stocks.
wlnum = GetOption( "FilterIncludeWatchlist" );
List = CategoryGetSymbols( categoryWatchlist, wlnum );
if ( Status("stocknum") == 0 ) // Generate ranking when we are on the very first symbol
{
StaticVarRemove( "values*" );
for ( n = 0; ( Symbol = StrExtract( List, n ) ) != ""; n++ )
{
SetForeign ( symbol );
// first criteria used for scoring
values1 = Crit1 ;
values2 = Crit2;
values3 = Crit3;
inIndex = NorgateIndexConstituentTimeSeries(tkindex);
RestorePriceArrays();
// here we write static variables holding the values
StaticVarSet ( "values1" + symbol, IIf(inIndex,values1,-1e9));
StaticVarSet ( "values2" + symbol, IIf(inIndex,values2,-1e9));
StaticVarSet ( "values3" + symbol, IIf(inIndex,values3,-1e9));
}
StaticVarGenerateRanks( "rank", "values1", 0, 1224 );
StaticVarGenerateRanks( "rank", "values2", 0, 1224 );
StaticVarGenerateRanks( "rank", "values3", 0, 1224 );
}
// retrieve rank positions
symbol = Name();
rank1 = StaticVarGet ( "rankvalues1" + symbol );
rank2 = StaticVarGet ( "rankvalues2" + symbol );
rank3 = StaticVarGet ( "rankvalues3" + symbol );
rank = 0.33 * rank1 + 0.33 * rank2 + 0.33 * rank3;