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 = 1000 + Criteria1 ;
// the other criteria used for scoring,
values2 = 1000 - criteria2;
values3 = 1000 - criteria3;
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, 1234 );
StaticVarGenerateRanks( "rank", "values2", 0, 1234 );
StaticVarGenerateRanks( "rank", "values3", 0, 1234 );
}
rank1 = StaticVarGet ( "rankvalues1" + symbol );
rank2 = StaticVarGet ( "rankvalues2" + symbol );
rank3 = StaticVarGet ( "rankvalues3" + symbol );
ranktemp = 0.33 * rank1 + 0.33 * rank2 + 0.33 * rank3;
My objective is to normalize ranktemp so that the first stock (according to criteria) has rank 1.
Is correct to use two loop (as in the following code) or does exist a better code?
wlnum = GetOption( "FilterIncludeWatchlist" );
List = CategoryGetSymbols( categoryWatchlist, wlnum ); //50
//SetOption("MaxOpenPositions", 3);
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 = 1000 + Criteria1 ;
// the other criteria used for scoring,
values2 = 1000 - criteria2;
values3 = 1000 - criteria3;
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, 1234 );
StaticVarGenerateRanks( "rank", "values2", 0, 1234 );
StaticVarGenerateRanks( "rank", "values3", 0, 1234 );
}
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 );
rank1 = StaticVarGet ( "rankvalues1" + symbol );
rank2 = StaticVarGet ( "rankvalues2" + symbol );
rank3 = StaticVarGet ( "rankvalues3" + symbol );
ranktemp = 0.33 * rank1 + 0.33 * rank2 + 0.33 * rank3;
inIndex = NorgateIndexConstituentTimeSeries(tkindex);
RestorePriceArrays();
// here we write static variables holding the values
StaticVarSet ( "ranktemp" + symbol, IIf(inIndex,1000/ranktemp,-1e9));
}
StaticVarGenerateRanks( "rank", "ranktemp", 0, 1234 );
}