The All Weather Portfolio (Amibroker Code)

The article could be found here.

Amibroker code:

In the settings, set the time frame you want: daily, weekly, etc.

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

if( Name() == “SPY” )
{

IIf( Name() == “SPY”,setPositionSize(29.75*leverage,spsPercentOfEquity),0);

Buy= C>0;
buyPrice=Close;
Sell= C>0;
SellPrice=Close;

 

}

if( Name() == “TLT” )
{

IIf( Name() == “TLT”,setPositionSize(39.75*leverage,spsPercentOfEquity),0);

Buy= C>0;
buyPrice=Close;
Sell= C>0;
SellPrice=Close;

 

}

if( Name() == “GLD” )
{

IIf( Name() == “GLD”,setPositionSize(7.4*leverage,spsPercentOfEquity),0);

Buy= C>0;
buyPrice=Close;
Sell= C>0;
SellPrice=Close;

 

}

if( Name() == “IEI” )
{

IIf( Name() == “IEI”,setPositionSize(14.9*leverage,spsPercentOfEquity),0);

Buy= C>0;
buyPrice=Close;
Sell= C>0;
SellPrice=Close;

 

}

if( Name() == “DBC” )
{

IIf( Name() == “DBC”,setPositionSize(7.4*leverage,spsPercentOfEquity),0);

Buy= C>0;
buyPrice=Close;
Sell= C>0;
SellPrice=Close;

 

}