forked from foorbar/tradingview
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkama_base_bb.txt
43 lines (37 loc) · 1.63 KB
/
kama_base_bb.txt
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
31
32
33
34
35
36
37
38
39
40
41
42
43
//@version=3
//The files in this repository are created by me and provided under the MIT License
//located at https://github.com/yield65/tradingview/blob/master/LICENSE
//If you find them useful please consider making a donation, thank you.
//Bitcoin: 3F636VrPCdnbfrdP5kS4C6fHWVBffXNKCu
//Litecoin: 33932ckE7i3oAQZxxSgLcvmbn8RAgTc2tk
//ETH: 0x53A43EF9E56908A9c868FBf2f1b9DE7B3486FDAF
//contact: [email protected]
study("Kaufman MA+BB", overlay=true, precision=0)
showbb = input(false, title="Display the BB?")
usekama = input(false, title="Use KAMA for BB?")
//Default Formula values
erp = input(10, title="Efficiency Ratio Periods", step=1, minval=1)
fastMA = input(2, step=1, minval=1, title="Fast Period")
slowMA = input(30, step=1, minval=1, title="Slow Period")
//Efficiency Ratio (ER)
change = abs(close-close[erp])
volatility = sum(abs(close - close[1]), erp)
er = change/volatility
fastAlpha = (2/(fastMA+1))
slowAlpha = (2/(slowMA+1))
sc = pow( er * (fastAlpha - slowAlpha ) + slowAlpha, 2)
kama = 0.0
kama := nz(kama[1]) + sc * (close - nz(kama[1]))
//====BB====
bbcolor = usekama ? fuchsia : silver
bb_mid = usekama ? kama : sma(close, 20)
dev = usekama ? 2.0 * stdev(close, 20) : 2.0 * stdev(close, 20)
bb_top = bb_mid + dev
bb_low = bb_mid - dev
//====BB====
plot(showbb ? na : kama, style=line, linewidth=2, color=yellow, transp=0 )
//display_bb
plot(showbb ? bb_top : na, color = bbcolor, linewidth=2, editable=true, transp=0, title="BB Top")
plot(showbb ? bb_mid : na, color = bbcolor, linewidth=2, editable=true, transp=0, title="BB Mid")
plot(showbb ? bb_low : na, color = bbcolor, linewidth=2, editable=true, transp=0, title="BB Low")
//