Timing The Market With Healthcare Stocks And The S&P 500 (Rotation Trading Strategy) (Amibroker Code)
Click here for the original article.
The strategy in plain English:
- We go long healthcare stocks at the close of April and sell at the close of September.
- We go long S&P 500 at the close of September and sell at the close of April.
Amibroker code:
Performance from the close of April until the close of September (sell in May and go away):
Buy=Month()!=Ref(Month(),1) AND Month()==4;
buyPrice=Close;
Sell= Month()!=Ref(Month(),1) AND Month()==9;
sellPrice=Close ;
Performance from the close of September until the close of April:
Buy=Month()!=Ref(Month(),1) AND Month()==9;
buyPrice=Close;
Sell= Month()!=Ref(Month(),1) AND Month()==4;
sellPrice=Close ;
The code of the rotation strategy:
setOption(“holdminbars”,1);
SetOption(“initialEquity”,100000);
SetOption(“accountmargin”,100/leverage);
setOption(“MaxOpenPositions”,1);
SetPositionSize(99.75,spsPercentOfEquity);
if( Name() == “SPY” )
{
Buy= Month()!=Ref(Month(),1) AND Month()==9;
buyPrice=Close;
Sell= Month()!=Ref(Month(),1) AND Month()==4 ;
sellPrice=Close ;
}
if( Name() == “FSPHX” )
{
Buy= Month()!=Ref(Month(),1) AND Month()==4;
buyPrice=Close;
Sell= Month()!=Ref(Month(),1) AND Month()==9 ;
sellPrice=Close ;
//ApplyStop(stopTypeNBar,stopModeBars,1,1) ;
}
Disclosure: We are not financial advisors. Please do your own due diligence and investment research or consult a financial professional. All articles are our opinions – they are not suggestions to buy or sell any securities.
