Home › Forums › Trading System Mentor Course Community › AmiBroker Coding and AFL › Sector Filter
- This topic is empty.
-
AuthorPosts
-
March 11, 2019 at 4:06 am #101907JulianCohenParticipant
Following on from Mike’s forum post I had a go at coding up the Sector filter into something we could use as a template to plug into our systems, but I had a few questions.
I made it and ADX filter as I’m not sure how many of us use RSI, I know I don’t.
Code:// Controls for sector filterenableSectorFilter = 1;
// Map the sector ID for this symbol to an index that represents the sector
sectID = sectorID();
switch(sectID)
{
case 1: tkSector = “$SP1500M”; break; // Basic Materials
case 2: tkSector = “$SP1500D”; break; // Consumer Cyclicals
case 3: tkSector = “$SP1500D”; break; // Consumer Non-cyclicals
case 4: tkSector = “$SP1500E”; break; // Energy
case 5: tkSector = “$SP1500F”; break; // Financials
case 6: tkSector = “$SP1500A”; break; // Healthcare
case 7: tkSector = “$SP1500I”; break; // Industrials
case 8: tkSector = “$SP1500T”; break; // Technology
case 9: tkSector = “$SP1500L”; break; // Telecommunication Services
case 10: tkSector = “$SP1500U”; break; // Utilities
default: tkSector = “$SP1500″; break;
}// Determine sector health using ADX of the sector index
pSector = Foreign(tkSector,”C”);
ADXSector = ADX(14);// Entry and exit rules
Breakout = C > Ref(HHV(C,250),-1);
Cond1 = Breakout AND IIf(enableSectorFilter, !IsNull(ADXSector) AND ADXSector > 25, True);
I’m not sure how to change the SP1500 to say Russell 1000, and also I noticed in the original code that Cyclical and non-cyclicals had the same sector ID which is probably an error?
Any errors in my code? And how do I apply this to Russell 1000?
March 11, 2019 at 5:23 am #109796Stephen JamesMemberJulian,
you can only use sectors that are in the data base – see the Groups folder under the Symbols tab.
Staples should be $SP1500S.
March 11, 2019 at 6:13 am #109800JulianCohenParticipantAh OK I understand.
So is it OK to use the sectors in S&P1500 and then confine the Entry Condition to NorgateIndexConstituentTimeSeries(“$RUI”);
March 11, 2019 at 11:11 pm #109801Stephen JamesMemberThat should be OK.
sectorID() identifies which sector each stock symbol is assigned to via the number of the sector (hover your cursor over the sectors under the Sectors folder in the symbols tab.
It then obtains rank for each sector symbol being used, e.g. $S&P1500M and combines that with the rank of individual symbols if they fall into corresponding sectorID.
To test add the combined rank and individual rank into exploration columns and if they return the same value there is probably and issue.
March 12, 2019 at 10:57 am #109804SaidBitarMemberthis what i used in the past
Code:_SECTION_BEGIN(“Universe Filter”);
//=================================================================================================SectTog = ParamToggle (“Sector Filter”,”Off|On”,0);
Energy = ParamToggle(“Energy”,”Included|Excluded”,0);
Materials = ParamToggle(“Materials”,”Included|Excluded”,0);
Industrials = ParamToggle(“Industrials”,”Included|Excluded”,0);
ConsDisc = ParamToggle(“Consumer Discretionary”,”Included|Excluded”,0);
ConsStap = ParamToggle(“Consumer Staples”,”Included|Excluded”,0);
Healthcare = ParamToggle(“Healthcare”,”Included|Excluded”,0);
Financials = ParamToggle(“Financials”,”Included|Excluded”,0);
InfoTech = ParamToggle(“Information Technologies”,”Included|Excluded”,0);
Telco = ParamToggle(“Telecommunication Services”,”Included|Excluded”,0);
Utilities = ParamToggle(“Utilities”,”Included|Excluded”,0);EnerCond = IIf( Energy == 0, InGics(“10”), InGics(“10”) == 0);
MatCond = IIf( Materials == 0, InGics(“15”), InGics(“15”) == 0);
IndusCond = IIf( Industrials == 0,InGics(“20”), InGics(“20”) == 0);
ConsDiscCond= IIf( ConsDisc == 0, InGics(“25”), InGics(“25”) == 0);
ConsStpCond = IIf( ConsStap == 0, InGics(“30”), InGics(“30”) == 0);
HealthCond = IIf( Healthcare == 0, InGics(“35”), InGics(“35”) == 0);
FinancialsCond = IIf( Financials == 0, InGics(“40”), InGics(“40”) == 0);
ITechCond = IIf( InfoTech == 0, InGics(“45”), InGics(“45”) == 0);
TelcoCond = IIf( Telco == 0, InGics(“50”), InGics(“50”) == 0);
UtiCond = IIf( Utilities == 0, InGics(“55”), InGics(“55”) == 0);Sectors = (EnerCond AND Energy == 0) OR (MatCond AND Materials == 0) OR (IndusCond AND Industrials == 0) OR
(ConsDiscCond AND ConsDisc == 0) OR (ConsStpCond AND ConsStap == 0) OR (HealthCond AND Healthcare == 0) OR
(FinancialsCond AND Financials == 0) OR (ITechCond AND InfoTech == 0) OR (TelcoCond AND Telco == 0) OR
(UtiCond AND Utilities == 0);SectFilt = IIf(SectTog,Sectors,1);
//=================================================================================================
_SECTION_END(); -
AuthorPosts
- You must be logged in to reply to this topic.