Dual Momentum Trading Strategy (Gary Antonacci) (Amibroker Code)
The original article can be found here.
Trading rules in plain English:
- Did S&P 500 outperform US Treasury Bills over the last 12 months?
- If the answer is no, then buy US Treasury Bills.
- If the answer is yes, did S&P 500 outperform the world index (ex. USA) over the last 12 months?
- If S&P 500 outperformed the world index, then buy S&P 500.
- If S&P 500 underperformed the world index, then buy the world index (global stocks).
Amibroker Code:
SetOption("initialEquity",100000);
Leverage=1.0 ;
SetOption("accountmargin",100/leverage);
setOption("MaxOpenPositions",6);
setOption("holdminbars",1);
SetTradeDelays( 0, 0, 0, 0 );
Fremmed=Foreign("SPY","close",fixup=1);
FremmedTo=Foreign("EFA","close",fixup=1);
FremmedTre=Foreign("AGG","close",fixup=1);
Rank1=ROC(Fremmed,12);
Rank2=ROC(FremmedTo,12);
Rank3=ROC(FremmedTre,12);
setPositionSize(99.95*leverage,spsPercentOfEquity);
// this section is just for visual confirmation of the strategy
SP500= IIf(Rank1>Rank2 AND Rank1>Rank3,1,0);
World= IIf(Rank1<Rank1 AND Rank1>Rank3,1,0);
Bonds= IIf(Rank1<Rank3,1,0);
Total= Sum(SP500 + World + Bonds,1);
Plot(Total,"Total",colorRed,styleLine);
Plot(Total,"SP500",colorblack,styleLine);
Plot(Total,"World",colorGreen,styleLine);
Plot(Total,"Bonds",colorBlue,styleLine);
// end of visual confirmation
if( Name() == "SPY" )
{
Buy= Rank1>Rank2 AND Rank1>Rank3 ;
buyPrice=Close;
Sell= C>0 ;
sellPrice= Close ;
}
if( Name() == "EFA" )
{
Buy= Rank2>Rank1 AND rank1>Rank3 ; ;
buyPrice=Close;
Sell= C>0;
sellPrice= Close ;
}
if( Name() == "AGG" )
{
Buy= Rank1<rank3 ;
buyPrice=Close;
Sell= C>0 ;
sellPrice= Close ;
}
