Rubber Band Strategy (Amibroker Code And Tradestation Code)
The original article can be found here.
The strategy in plain English:
- Calculate a 10-day average of the (High minus Low – (H-L)). That is the “ATR”.
- Calculate the High of the last 10 days.
- Calculate a band 2.5 times below the 10-day High using the average from point number 1 (ATR).
- If XLP closes below the band in number 3, then go long at the close.
- Exit when the close is higher than yesterday’s high.
Amibroker code:
range=MA((H-L),10);
OddisHigh=HHV(H,10);
OddisBand=OddisHigh – (range*2.5);
Buy=Close<OddisBand ;
buyprice= Close;
Sell= C>Ref(H,-1);
sellPrice= Close;
Tradestation code:
{
Rubber band strategy
https://www.quantifiedstrategies.com/lessons/rubber-band-strategy-amibroker-code/
}
Inputs:
Lookback(10),
BandWidth(2.5);
Vars:
RangeAvg(0),
HighestHigh(0),
RubberBand(0);
RangeAvg = Average(Range, Lookback);
HighestHigh = Highest(H, Lookback);
RubberBand = HighestHigh - (RangeAvg * BandWidth);
if C < RubberBand Then buy this bar on close;
if C > H[1] Then sell this bar on close;
