thinkscript - Bollinger Band Alert

This script will sound an alert when a candle is outside the upper/lower bollinger band. It also looks at the candle size based on ATR to filter out some of the alerts. It may alert several times per candle if it continously ticks above/below the bollinger band and it may disappear entirely if it closes inside.

Outside Bollinger Band
input bollinger_length = 20;
input bollinger_devs = 2.0;
input bollinger_price = close;
input atr_length = 14;
input alert_text = "Outside Bollinger Band";
input use_alerts = {false, default true};
input alert_type = {default "BAR", "ONCE", "TICK"};
input alert_sound = {"Bell", "Chimes", default "Ding", "NoSound", "Ring"};

def upper = BollingerBands(length = bollinger_length, price = bollinger_price, "num dev dn" = -bollinger_devs, "num dev up" = bollinger_devs)."UpperBand";
def middle = BollingerBands(length = bollinger_length, price = bollinger_price)."MidLine";
def lower = BollingerBands(length = bollinger_length, price = bollinger_price, "num dev dn" = -bollinger_devs, "num dev up" = bollinger_devs)."LowerBand";

def atr = ATR(length = atr_length);

def condition1 = (low < lower) and (close < open) and (open - close > atr);
def condition2 = (high > upper) and (close > open) and (close - open > atr);

def at = alert_type;
Alert((condition1 or condition2) and use_alerts, alert_text, if at == 1 then Alert.ONCE else if at == 2 then Alert.TICK else Alert.BAR, alert_sound);

plot Above = condition1;

plot Below = condition2;


I am not a registered financial adviser/broker/anything. Use this information for entertainment/informational purposes only. Any tickers mentioned are not recommendations to buy/sell/or sell short. They are used as examples only.

Please remember that past performance may not be indicative of future results.