Bollinger Bands Reversal to Mean

barbaros

Administrator
Staff member
Platform
  1. Thinkorswim
Here is a simple indicator that signals when reversal to midline of Bollinger Bands is expected.

Code:
# Bollinger Bands Reversal to Mean
# Free for use. Header credits must be included when any form of the code included in this package is used.
# Any indicator built on this indicator needs to attribute the original author's work
# v1.0 - barbaros - released for b4indicators.com


def upper = BollingerBands().UpperBand;
def mid = BollingerBands().MidLine;
def lower = BollingerBands().LowerBand;

plot buy = low[1] < lower[1] and close > high[1] and close < mid;
buy.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
buy.SetDefaultColor(Color.CYAN);

plot sell = high[1] > upper[1] and close < low[1] and close > mid;
sell.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
sell.SetDefaultColor(Color.MAGENTA);

Alert(buy[1], "Buy", Alert.BAR, Sound.Ding);
Alert(sell[1], "Sell", Alert.BAR, Sound.Ding);

8D9yA2H.png
 

barbaros

Administrator
Staff member
Not tested:

Code:
# Bollinger Bands Reversal to Mean (Watchlist Column)
# Free for use. Header credits must be included when any form of the code included in this package is used.
# Any indicator built on this indicator needs to attribute the original author's work
# v1.0 - barbaros - released for b4indicators.com


def upper = BollingerBands().UpperBand;
def mid = BollingerBands().MidLine;
def lower = BollingerBands().LowerBand;
def buy = low[1] < lower[1] and close > high[1] and close < mid;
def sell = high[1] > upper[1] and close < low[1] and close > mid;
def direction = if buy then 1 else if sell then -1 else direction[1];

AddLabel(yes, if direction crosses above 0 then "Buy" else if direction crosses below 0 then "Sell" else if direction == 1 then "Long" else if direction == -1 then "Short" else "Neutral");
 
Top