Bollinger Band Stops Indicator for ThinkorSwim

BenTen

BenTen

Administrative
Staff
VIP
I didn't find a BB stops indicator on TV, so I wrote one myself. You can select various ma types as a base anchor for the calculations. This indicator can have various use cases similar to Supertrend or Parabolic SAR: as a trend indicator, as a training stop loss,...



thinkScript Code

Code:
# Bollinger Band Stops
# Author: Kory Gill (@korygill)
# Converted for BenTen at useThinkScript.com
# Original Idea: https://www.tradingview.com/script/7kI0k6Xp-Bollinger-Band-stops-JD/

declare upper;
declare once_per_bar;

input baseMA = {default sma, ema, wma, vwma, swma, dema, hullema, tema};
input length = 20;
input mult = 1; #hint mult: 0.001 to 50
input colorFill = yes;

def vClose = close;
def bn = BarNumber();
def nan = double.NaN;

def ema1 = MovingAverage(AverageType.EXPONENTIAL, vClose, length);
def ema2 = MovingAverage(AverageType.EXPONENTIAL, ema1, length);
def ema3 = MovingAverage(AverageType.EXPONENTIAL, ema2, length);
def tema = 3 * (ema1 - ema2) + ema3;

def wma = MovingAverage(AverageType.WEIGHTED, vClose, length);

def basis;
switch (baseMA)
{
case sma: basis = MovingAverage(AverageType.SIMPLE, vClose, length);
case ema: basis = MovingAverage(AverageType.EXPONENTIAL, vClose, length);
case wma: basis = MovingAverage(AverageType.WEIGHTED, vClose, length);
case vwma: basis = MovingAverage(AverageType.EXPONENTIAL, vClose, length);
case swma: basis = wma[3]/6 + 2*wma[2]/6 + 2*wma[1]/6 + wma;
case dema: basis = ema2;
case hullema: basis = MovingAverage(AverageType.HULL, vClose, length);
case tema: basis = tema;
}

def dev = mult * stdev(vClose, length);
def upper = basis + dev;
def lower = basis - dev;

def up = if bn == 1
         then nan
         else if Crosses(vClose, upper, CrossingDirection.ABOVE)
         then 1
         else if Crosses(vClose, lower, CrossingDirection.BELOW)
         then 0
         else up[1];

def dn = if bn == 1
         then nan
         else if Crosses(vClose, lower, CrossingDirection.BELOW)
         then 1
         else if Crosses(vClose, upper, CrossingDirection.ABOVE)
         then 0
         else dn[1];

def changeUp = dn[1] and up;
def changeDn = up[1] and dn;
def stopLine = if up then lower else if dn then upper else nan;

plot p1 = stopLine;
p1.SetLineWeight(2);
p1.AssignValueColor(if stopLine == upper then Color.Red else Color.Green);

AddCloud(stopLine, vClose, CreateColor(80,0,0), CreateColor(0,80,0));

#plot pChangeDn = if changeDn then lower else nan;
#plot pChangeUp = if changeUp then upper else nan;
#pChangeDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
#pChangeUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#pChangeDn.SetDefaultColor(Color.Red);
#pChangeUp.SetDefaultColor(Color.Green);
 
M

mrwind425

New member
2019 Donor
VIP
@BenTen have you tried to use it on 3m or 5m time frame yet?
 
J

john3

Active member
2019 Donor
@BenTen So the stop-loss is simply Bollinger Band's 1 standard deviation?
 
BenTen

BenTen

Administrative
Staff
VIP
@mrwind425 @john3 I have not tested this. I found it interesting so I asked @korygill to convert it.
 
J

john3

Active member
2019 Donor
I added TOS' Bollinger Bands with 1 Std and it matches the "stop loss."
 
korygill

korygill

Active member
VIP
There are 8 choices for the baseMA. BollingerBands use the Simple moving average, so that will match. The other 7 provide different results.
 
U

urikreizer

New member
Hi, how can I remove the background colour zone of the indicator? Thanks in advance!
 
BenTen

BenTen

Administrative
Staff
VIP
@urikreizer Go to your indicator’s settings > Colorfill.
 
osamakhdir

osamakhdir

New member
HI
Question, please
I am building a new strategy for ( EUR USD ) Just that was the latest version of Indicator bollinger bands stop v2

Are there updated versions?
 
G

gsquared28

New member
VIP
@BenTen Anyway to add an alert when the trend changes?
 

Similar threads

Top