本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("EMA 20 Angle Meter", overlay=true)
// Inputs
emaLength = input.int(20, "EMA Length")
lookback = input.int(5, "Slope Lookback Bars", minval=1)
atrLength = input.int(14, "ATR Normalization Length")
flatThreshold = input.float(5.0, "Flat Threshold (Degrees)")
// Calculations
ema20 = ta.ema(close, emaLength)
atrValue = ta.atr(atrLength)
// Normalized slope
slope = atrValue != 0 ? (ema20 - ema20[lookback]) / (atrValue * lookback) : 0
// Convert to degrees
angle = math.atan(slope) * 180 / math.pi
// Colors
emaColor = angle > flatThreshold ? color.lime :
angle < -flatThreshold ? color.red : color.yellow
// Plot EMA
plot(ema20, "EMA 20", color=emaColor, linewidth=2)
// Display angle
var table angleTable = table.new(position.top_right, 2, 2,
bgcolor=color.black, border_width=1)
if barstate.islast
table.cell(angleTable, 0, 0, "EMA 20 ANGLE",
text_color=color.white)
table.cell(angleTable, 1, 0, str.tostring(angle, "#.##") + "°",
text_color=emaColor, text_size=size.large)
trend = angle > flatThreshold ? "BULLISH" :
angle < -flatThreshold ? "BEARISH" : "FLAT"
table.cell(angleTable, 0, 1, "TREND", text_color=color.white)
table.cell(angleTable, 1, 1, trend, text_color=emaColor)