You are on page 1of 1

//4 Moving Average + Bollinger Bands in one indicator by ナミ.

Modified from
Alessiof Script.
//Credit to the original author.

//You can select the MA type between simple moving average (sma) or exponential
moving average (ema) in MA type.

study(title="4MA (10,50,100,200) + Bollinger Bands", shorttitle="4MA+BB", overlay =


true )

//MA
ma_type = input(title="MA Type", defval="sma")
Length1 = input(10, minval=1, title="MA 1")
Length2 = input(50, minval=1, title="MA 2")
Length3 = input(100, minval=1, title="MA 3")
Length4 = input(200, minval=1, title="MA 4")
xPrice = close
MA1 = ma_type == "sma" ? sma(xPrice, Length1) : ema(xPrice, Length1)
MA2 = ma_type == "sma" ? sma(xPrice, Length2) : ema(xPrice, Length2)
MA3 = ma_type == "sma" ? sma(xPrice, Length3) : ema(xPrice, Length3)
MA4 = ma_type == "sma" ? sma(xPrice, Length4) : ema(xPrice, Length4)
plot(MA1, color=green, linewidth=1, transp=20, title="MA1")
plot(MA2, color=orange, linewidth=1, transp=20, title="MA2")
plot(MA3, color=blue, linewidth=1, transp=20, title="MA3")
plot(MA4, color=red, linewidth=1, transp=20, title="MA4")

//BB
length = input(20, minval=1, title="BB length")
src = input(close, title="Source")
stdev = input(2.0, minval=0.001, maxval=50)
basis = sma(src, length)
dev = stdev * stdev(src, length)
upper = basis + dev
lower = basis - dev
plot(basis, title="BB Median", color=#872323)
p1 = plot(upper, title="BB Upper", color=teal)
p2 = plot(lower, title="BB Lower", color=teal)
fill(p1, p2, color=#198787, transp=95, title="BB Hlines Background")

You might also like