The Death Cross (Amibroker And Tradestation Code)
The article can be found here.
Amibroker code:
Below is the code to measure the returns after N days after a Death Cross.
The code uses the optimization function.
oddis=Optimize(“Days after entry”,10,10,200,10);
Buy= Cross( MA(C,200),MA(C,50) );
buyPrice=Close;
Sell= 0;
SellPrice=Close;
applyStop(stopTypeNBar,stopModeBars,oddis,1);
The code below buys a Golden Cross and sells when there is a Death Cross:
Buy= Cross(MA(C,50),MA(C,200));
BuyPrice=Close;
Sell= Cross(MA(C,200),MA(C,50));
SellPrice=Close;
Tradestation code:
{
This code to measure the returns after N days after a Death Cross (Strategy 96A)
}
Inputs: HoldBars(10);
if Average(Close, 200) cross over Average(Close, 50) Then
Buy this bar on close;
if Barssinceentry(0) >= HoldBars Then
Sell this bar on close;
{
The code below buys a Golden Cross and sells when there is a Death Cross (Strategy 96B)
}
Inputs:
FastLookback(50),
SlowLookback(200);
if Average(Close, FastLookback) cross over Average(Close, SlowLookback) Then
Buy this bar on close;
if Average(Close, SlowLookback) cross over Average(Close, FastLookback) Then
Sell this bar on close;
