Bollinger Bands Squeeze Strategy (Amibroker And Tradestation Code)
The original article can be found here.
Trading rules in plain English:
- The RSI of the bands must be lower than 45
- The close must set a new 5-day high
- We sell after 20 weeks
Amibroker code:
oddis=Optimize("Trading day",20,1,25,1);
band = BBandTop(C,10,2) - BBandBot(C,10,2) ;
RSIband=RSIa(band,10);
Plot(band,"Band Diff",colorRed,styleLine) ;
Buy= RSIband<45 AND C>Ref(HHV(C,5),-1) ;
buyPrice= Close;
Sell= 0;
sellPrice= Close ;
ApplyStop(stopTypeNBar,stopModeBars,oddis,1);
Tradestation code:
{
Bollinger Bands Squeeze Strategy
https://www.quantifiedstrategies.com/lessons/bollinger-bands-squeeze-strategy-amibroker-code/
}
Inputs:
BBLookback(10),
BBNumDevs(2),
RSILookback(10),
RSITreshold(45),
HoldBars(20);
Vars:
Band(0),
RsiBand(0);
Band = BollingerBand(Close, BBLookback, BBNumDevs) - BollingerBand(Close, BBLookback, -BBNumDevs);
RSIBand = RSI(Band, RSILookback);
if RSIBand < RSITreshold AND Close > Highest(Close, 5)[1] Then
Buy this bar on close;
if Barssinceentry(0) >= HoldBars Then
Sell this bar on close;
