Lumber/Gold Ratio Trading Strategy For Stocks And Bonds (Amibroker Code)

The original article.

Trading rules:

  • Make a lumber/gold ratio;
  • When the ratio is higher than the month before, we go long S&P 500 (SPY);
  • When the ratio is lower than the month earlier, we go long bonds (TLT).

As a proxy for lumber, we use the ETF with the ticker code WOOD. That ticker is not very liquid. For gold, we use the ETF with the ticker code GLD.

Amibroker code:

SetOption("initialEquity",100000);
Leverage=1.0 ;
SetOption("accountmargin",100/leverage);
setOption("MaxOpenPositions",3);
setOption("holdminbars",1);
SetTradeDelays( 0, 0, 0, 0 ); // 	SetTradeDelays( buydelay, selldelay, shortdelay, coverdelay ) 


setPositionSize(99.75*leverage,spsPercentOfEquity);

Fremmed=Foreign("WOOD","close",fixup=1);
FremmedTo=Foreign("GLD","close",fixup=1);

Ratio= Fremmed/FremmedTo ;
MaRatio = MA(ratio,oddis);


if( Name() == "SPY" )
{


Buy= ratio>Ref(ratio,-1) ;
BuyPrice=Close;
Sell= ratio<Ref(ratio,-1) ;
SellPrice=Close;


}


if( Name() == "TLT" )
{

Buy=ratio<Ref(ratio,-1) ;
BuyPrice=Close;
Sell= ratio>Ref(ratio,-1) ;
SellPrice=Close;


}