本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=4
study(title="Keltner Trend", overlay=true)
len = input(title="Period", type=input.integer, defval=20, minval=1)
mult = input(title="Multiplier", type=input.float, defval=1.0, minval=1)
useTrueRange = input(title="Average True Range", defval=true)
src = input(hlc3, title="Source")
price = sma(src, len)
range = useTrueRange ? tr : high - low
movement = sma(range, len) * mult
upper = price + movement
lower = price - movement
bullish = src > upper[1]
bearish = src < lower[1]
c = barssince(bullish and not bearish) <= barssince(bearish and not bullish) ? color.lime : color.red
plot(price, color=c, title="Mid", transp=70, linewidth=1)
top = plot(upper, color=c, title="Upper", transp=20, linewidth=2)
bot = plot(lower, color=c, title="Lower", transp=20, linewidth=2)
fill(top, bot, c, transp=88)