-
Notifications
You must be signed in to change notification settings - Fork 2
/
Double Bollinger Bands
30 lines (28 loc) · 1.3 KB
/
Double Bollinger Bands
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//@version=5
indicator(shorttitle="BB", title="Bollinger Bands", overlay=true, timeframe="", timeframe_gaps=true)
length = input.int(20, minval=1)
maType = input.string("SMA", "Basis MA Type", options = ["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"])
src = input(close, title="Source")
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")
mult2 = input.float(3.0, minval=0.001, maxval=50, title="StdDev2")
ma(source, length, _type) =>
switch _type
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)
basis = ma(src, length, maType)
dev = mult * ta.stdev(src, length)
dev2 = mult2 * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev
upper2 = basis + dev2
lower2 = basis - dev2
offset = input.int(0, "Offset", minval = -500, maxval = 500, display = display.data_window)
plot(basis, "Basis", color=#FF6D00, offset = offset)
p1 = plot(upper, "Upper", color=#2962FF, offset = offset)
p2 = plot(lower, "Lower", color=#2962FF, offset = offset)
plot(upper2, "Uppest", color=#ff29a26b, linewidth=2, offset = offset)
plot(lower2, "Lowest", color=#ff29a26b, linewidth=2, offset = offset)
fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))