Ranking symbols based on Sectoral Indices performance

I have been designing a trading system, where individual stocks are ranked on their own ROC as well as the ROC of Sectoral Indices.
The problem which i faced was, how to get the symbols belonging to different indices for ranking.

This system is very similar to the article, [http://www.amibroker.com/kb/2016/01/30/separate-ranks-for-categories-that-can-be-used-in-backtesting/], but instead of sectorId(), can we use Sectoral indices from Symbols menu? I have no idea.

Seniors, I have very little tweaking knowledge of AFL:grinning: and above 50, very hard time to learn the skill whole new. Kindly help.

As mentioned in the referenced article, symbols canbe accessed from watchlist.

// watchlist should contain all symbols included in the test
wlnum = GetOption( "FilterIncludeWatchlist" );
List = CategoryGetSymbols( categoryWatchlist, wlnum ) ;

Similarly if i want to access indices from Indexes category, following code does not seem to work:
indnum = GetOption( "FilterIncludeIndex" );
indList = CategoryGetSymbols( categoryIndex,indnum) ;

Please correct me if i am wrong

@Tomasz(or any seniors), I don't find any article or post about using indices in Indexes menu. How do we rank them based on their performance?.

Please help.


If you can't write AFL yourself you can always hire 3rd party: Third party services, blogs, courses, books, add-ons

Thank you very much for your kind advice. Going to hire 3rd party option was always there, even before starting this thread and i wouldn't have spent hours searching relevant threads/material on this forum, apart from similar efforts elsewhere on the net.
I never asked for ready to use piece of code. I just asked for the references/ materials related to my strategy's requirements. I thought this community of experts would at least help the beginners like me in the process of self learning.


1 Like

@shrinivasb the posts on this forum and in the Official Knowledge Base are the only reference material I am familiar with to guide you on your code. You have already reviewed that material so I personally have no other information to add.

As a reminder, perhaps your database and data vendor supply different lists, but for me there was no use in using

indnum = GetOption( "FilterIncludeIndex" );
indList = CategoryGetSymbols( categoryIndex,indnum);

as my "Indexes" list has 1,500 symbols and most have nothing to do with Sectors. That is why in the other forum thread the list of sector Indices was listed as


Those symbols represent the various Sector Indices (or Indexes) in my data.

Good luck.

@shrinivasb you seem to have mentioned two different problems. Is your issue that you cannot access the list of indices, or that you don't know how to rank them based on performance?

If the problem is not being able to access the list, then perhaps you could use a solution like the one suggested by @portfoliobuilder, or you could add the indices of interest to a watch list.

You can add all the sector indices into a watchlist and then extract them.

   // generate separate ranks for each category from the list
    for( i = 1; ( category = StrExtract( categoryList, i ) ) != ""; i++ )
        StaticVarGenerateRanks( "rank", "values" + category + "_", 0, 1224 );
        StaticVarGenerateRanks( "top", "ValuesToSort", 3, 1224 ); // top-N mode 

	StaticVarGenerateRanks( "bot", "ValuesToSort", -3, 1224 ); // bottom-N mode 

supposing that a buy signal be generated for top -N mode stocks and a sell signal for bottom -N mode stocks, how should it be coded. As i understand, StaticVarGetRankedSymbols can not be used,as it gives comma -seperated list.