

Such ranking information can be used in backtest and sample rules included at the end of the code use rank information to allow only two top-scored symbols to be traded. We can also change Filter variable definition to Filter = 1 Running the exploration will show two top-ranked symbols for each of the sectors:

Our test should be applied to a watchlist, which contains all symbols we want to include in our ranking code: SetPositionSize ( 1, spsPercentOfEquity ) PositionScore = IIf ( m != Ref ( m , - 1 ), score, scoreNoRotate )

switch symbols at the beginning of the month only If( Status ( "Action" ) = actionExplore ) SetSortColumns ( 2, 5, 4 ) Rank = StaticVarGet ( "rank" + "values" + category + "_" + symbol ) ĪddTextColumn ( SectorID ( 1 ), "Sector" ) ĪddColumn ( SectorID (), "Sector No", 1 ) Values = StaticVarGet ( "values" + category + "_" + symbol ) StaticVarGenerateRanks ( "rank", "values" + category + "_", 0, 1224 ) generate separate ranks for each category from the listįor( i = 1 ( category = StrExtract ( categoryList, i ) ) != "" i ++ ) StaticVarSet ( "values" + category + "_" + symbol, values ) write ranked values to a static variable in this example we will use 10-bar rate-of-change write our ranking criteria to a variable If( ! StrFind ( categoryList, "," + category + "," ) ) categoryList += NumToStr ( category, 1, 0 ) + "," cleanup variables created in previous runs (if any)įor( n = 0 ( Symbol = StrExtract ( List, n ) ) != "" n ++ ) List = CategoryGetSymbols ( categoryWatchlist, wlnum ) Wlnum = GetOption ( "FilterIncludeWatchlist" ) watchlist should contain all symbols included in the test The static variables names are based on category number (sectors in this example) and that allows to create separate ranks for each sector. The formula presented below iterates though the list of symbols included in the test, then calculates the scores used for ranking and writes them into static variables. This can be done with ranking functionalities provided by StaticVarGenerateRanks function. When we want to develop a trading system, which enters only N top-scored symbols from each of the sectors, industries or other sub-groups of symbols ranked separately, we should build appropriate ranks for each of such categories.
