Double Death Cross In Trading (Amibroker And Tradestation Code)

The original article can be found here.

The strategy in plain English:

or

  • The 50-day simple moving average must cross below the 200-day simple moving average, and the close must be below the 100-day moving average.

We exit after N-days. We use Amibroker as our backtesting platform (please read our Amibroker review). To vary our holding period we use Amibroker’s optimizing feature.

Amibroker code:

oddis=Optimize(“Exit after N-days”,200,20,200,10) ;

Buy= ( Cross(MA(C,100),MA(C,50)) AND MA(C,50)<MA(C,200) )
OR
( Cross(MA(C,200),MA(C,50)) AND MA(C,50)<MA(C,100) )
;
buyPrice=Close;
Sell= 0 ;
sellPrice=Close ;

applyStop(stopTypeNBar,stopModeBars,oddis,1);

Tradestation code:

{
Strategy 129 - Double death cross strategy
The 50-day simple moving average must cross below the 100-day simple moving average, and the close must be below the 200-day moving average.
or
The 50-day simple moving average must cross below the 200-day simple moving average, and the close must be below the 100-day moving average.
We exit after N-days.
}

Inputs:
	LookbackFast(50),
	LookbackMid(100),
	LookbackSlow(200),
	HoldBars(200);

Vars:
	mafast(0),
	mamid(0),
	maslow(0);

mafast = Average(Close, LookbackFast);
mamid = Average(Close, LookbackMid);
maslow = Average(Close, LookbackSlow);

if ((mamid cross over mafast) and (mafast < maslow)) OR ((maslow cross over mafast) and (mafast < mamid)) then 
	buy this bar on close;

if Barssinceentry(0) >= HoldBars Then
	sell this bar on close;