BB & Keltner

AsyrafDaud · study · 47 行 · 点赞 384 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=3
//created by Asyraf Daud (March 19, 2018)
 
study(title="BB & Keltner", overlay=true)
 
length = input(20, minval=1, title="Length")
src = input(close, title="Source")
 
//SD2 BB
 
B2mult = input(2.0, minval=0.001, maxval=50, title="Band StDev 2")
B2basis = sma(src, length)
B2dev = B2mult * stdev(src, length)
B2upper = B2basis + B2dev
B2lower = B2basis - B2dev
 
 
//SD1 BB
 
B1mult = input(1.0, minval=0.001, maxval=50, title="Band StDev 1")
B1basis = sma(src, length)
B1dev = B1mult * stdev(src, length)
B1upper = B1basis + B1dev
B1lower = B1basis - B1dev
 
plot(B2basis, color=teal, linewidth=3)
p1 = plot(B2upper, color=teal, linewidth=3, title="Band SD2 Upper")
p2 = plot(B2lower, color=teal, linewidth=3, title="Band SD2 Lower")
p3 = plot(B1upper, color=orange, linewidth=2, title="Band SD1 Upper")
p4 = plot(B1lower, color=orange, linewidth=2, title="Band SD1 Lower")
 
 
//Keltner
useTrueRange = input(true)
 
Kmult = input(1.5, title="Keltner Range")
Kma = ema(src, length)
Krange = useTrueRange ? tr : high - low
Krangema = ema(Krange, length)
Kupper = Kma + Krangema * Kmult
Klower = Kma - Krangema * Kmult
 
p5 = plot(Kupper, color=fuchsia, linewidth=1, style=circles, title="Keltner Upper")
p6 = plot(Klower, color=fuchsia, linewidth=1, style=circles, title="Keltner Lower")
 
fill(p1, p2, color=gray, title="Band SD2 Background")
fill(p3, p4, color=gray, title="Band SD1 Background")

← 返回列表