Home › Forums › Trading System Mentor Course Community › AmiBroker Coding and AFL › Ranking using strong sectors
- This topic is empty.
-
AuthorPosts
-
April 21, 2020 at 7:09 am #102013TrentRothallParticipant
I found some code here and adapted it so it can be used as a ranking for the cbt in a trend or MR system.
It ranks the sectors then determines which one the stock belongs too to get its ranking.
Might be useful for someone… but needs to be checked and verified. There is also probably a easier way but this seems to work.
Quote://=================================================================================
// Ranks Sectors
//=================================================================================AuSectorList = “$XNJ.au,$XDJ.au,$XEJ.au,$XFJ.au,$XHJ.au,$XIJ.au,$XMJ.au,$XRE.au,$XSJ.au,$XTJ.au,$XUJ.au”;
if( Status( “stocknum” ) == 0 )
{StaticVarRemove( “sector*” );
// Sector rank
for( i = 0; ( sec = StrExtract( Ausectorlist, i ) ) != “”; i++ )
{
SetForeign( sec );
sectormom = ROC( C, 100);
RestorePriceArrays();
StaticVarSet( “sectormom” + sec, sectormom );}
StaticVarGenerateRanks( “sectorrank”, “sectormom”, 0, 1224 );
}
“3”;StockSector = StrLeft( GicsID( 0 ),2); // finds which sector the stocks in using the first 2 digits of GCIS id
sec = “”;if( stocksector == “10” )
sec = “$XEJ.au”;if( stocksector == “15” )
sec = “$XMJ.au”;if( stocksector == “20” )
sec = “$XNJ.au”;if( stocksector == “25” )
sec = “$XDJ.au”;if( stocksector == “30” )
sec = “$XSJ.au”;if( stocksector == “35” )
sec = “$XHJ.au”;if( stocksector == “40” )
sec = “$XFJ.au”;if( stocksector == “45” )
sec = “$XIJ.au”;if( stocksector == “50” )
sec = “$XTJ.au”;if( stocksector == “55” )
sec = “$XUJ.au”;if( stocksector == “60” )
sec = “$XRE.au”;sectorrank = StaticVarGet( “sectorranksectormom” + sec );
sectormom = StaticVarGet( “sectormom” + sec );“Sector : “+printf(sec);
“Sector momentum: “+NumToStr(sectormom);
“Sector rank: “+NumToStr(sectorrank);April 21, 2020 at 9:33 am #111317Howard LaskParticipantThere was a useful post on the Amibroker knowledge base designed to enter strongest stocks in strongest sectors, I have not implemented however code looks like it can be used for US Markets too: http://www.amibroker.com/kb/2016/01/30/separate-ranks-for-categories-that-can-be-used-in-backtesting/
May 20, 2020 at 2:44 am #111318TrentRothallParticipantI’ve been trying to test using the sector ranking as both position score and a entry condition. eg sectormom > x
The first issue i hit was not showing and trades pre 2019 in a backtest. This was because the sector $XRE.au seems to be added in late 2017. There is a work around here: https://norgatedata.com/amibroker-faq.php#limitedresults
But now if a stock is in the sector $XRE.au currently, it doesn’t show a buy until 2019 even if it meets the previous criteria.
I’ve tried to add:
Code:sectorUp = sectormom > x or sectormom == null;Anyone ave any ideas? or is that makes no sense ill try and explain it again.
May 20, 2020 at 5:06 am #111472Nick RadgeKeymasterI’d be a little cautious with using sectors in Australia. Some sectors are heavily influenced by a single stock, ie. Telstra or CSL
May 20, 2020 at 6:14 am #111475TrentRothallParticipantYeah ok, thanks Nick. I’ll keep that in mind. Cheers
May 21, 2020 at 7:01 am #111476BenJefferyMemberHey Trent, I looked at something like this a while ago, they only populate the current sector. Conclusion I came to was you would need something like norgate historical sector constituents for it to work.
May 22, 2020 at 2:34 am #111486TrentRothallParticipantThink i found my answer to above.
Just need to use Isempty() function.
ie sectormom > x or Isempty(sectormom);
-
AuthorPosts
- You must be logged in to reply to this topic.