本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=3
study(title="Keltner Channels Width", shorttitle="KCW", overlay=false)
useTrueRange = input(true)
length = input(20, minval=1)
mult = input(2.25)
src = input(close, title="Source")
wp = input(20, title="Width Period")
highest_period = input(100,title="Highest Width (bars back)")
highest_smoothing = input(100, title="Highest Width Smoothing")
ma = sma(src, length)
range = useTrueRange ? tr : high - low
rangema = ema(range, length)
upper = ma + rangema * mult
lower = ma - rangema * mult
width = sma((upper-lower)/ma,wp)
highest_width = sma(highest(width,highest_period),highest_smoothing)
width_above = if width > highest_width
width
width_below = if width < highest_width
width
below_highest = if width >= highest_width
highest_width
l = plot(0)
z = plot(below_highest, style=cross)
y = plot(width_below, style=cross)
x = plot(width_above, style=cross)
w = plot(width, color=black, title="Width",linewidth=2)
h = plot(highest_width, color=black, title="Highest",linewidth=2)
fill(x,h,color=#ff5e71,transp=10)
fill(l,y,color=#90d17d,transp=10)
fill(l,z,color=#90d17d,transp=10)