#### 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);
```