Sugar Futures Strategy (Amibroker And Tradestation Code)
The original strategy can be found here.
The strategy in plain English:
- Buy when the price breaks above the 350-day moving average plus a seven-day ATR.
- Sell when the price breaks below the 350-day moving average deducted a seven-day ATR.
Amibroker code:
ATRUpperBand = MA(C,350)+ATR(3) ;
ATRLowerBand = MA(C,350)-ATR(3) ;
Buy = Cross(C,Ref(ATRUpperBand,-1)) ;
BuyPrice= Close ;
Sell = Cross(Ref(MA(C,350),-1),Close) ;
SellPrice = Close ;
Tradestation code:
{
Strategy - sugar futures
https://www.quantifiedstrategies.com/lessons/sugar-futures-strategy-amibroker-code/
}
Inputs:
Lookback(350),
AtrLength(3);
Vars:
AtrUpperBand(0),
AtrLowerBand(0);
AtrUpperBand = Average(C, Lookback) + AvgTrueRange(AtrLength);
AtrLowerBand = Average(C, Lookback) - AvgTrueRange(AtrLength);
if C cross over AtrUpperBand[1] Then
buy this bar on close;
if C cross under Average(C, Lookback) Then
sell this bar on close;
