Keltner Trend

FractalTrade_ · study · 26 行 · 点赞 620 · TradingView 原页

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

Pine Script

//@version=4
study(title="Keltner Trend", shorttitle="KT", overlay=true, resolution="")
length = input(21, minval=1)
mult = input(1.0, "Multiplier")
src = input(hlc3, title="Source")
exp = input(true, "Use Exponential MA")
BandsStyle = input("Average True Range", options = ["Average True Range", "True Range", "Range"], title="Bands Style")
atrlength = input(13, "ATR Length")
esma(source, length)=>
	s = sma(source, length)
	e = ema(source, length)
	exp ? e : s
ma = esma(src, length)
rangema = BandsStyle == "True Range" ? rma(tr(true), length) : BandsStyle == "Average True Range" ? atr(atrlength) : rma(high - low, length)
upper = ma + rangema * mult
lower = ma - rangema * mult
float trend = 0
trend := close > upper? 1 : close < lower? 0 : fixnan(trend[1])
fcol1 = trend == 1? color.rgb(255, 255, 255, 95) : color.rgb(255, 255, 255, 100)
fcol2 = trend == 0? color.rgb(255, 255, 255, 95) : color.rgb(255, 255, 255, 100)
 
u = plot(trend == 1? upper : na, color=color.aqua, style = plot.style_circles, title="Upper")
m = plot(ma, color=color.white, title="Basis")
l = plot(trend == 0? lower: na, color=color.red, style = plot.style_circles, title="Lower")
fill(u, m, color = fcol1  , title="Background")
fill(l, m, color = fcol2  , title="Background")

← 返回列表