Files
tradingview/ema26_ema52.pine
2026-03-24 16:36:47 +08:00

37 lines
2.0 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//@version=6
indicator("多周期 EMA", shorttitle="EMA", overlay=true)
// 参数
src = input.source(close, "价格源")
showEma26 = input.bool(true, "显示 EMA26")
showEma52 = input.bool(true, "显示 EMA52")
showEma104 = input.bool(false, "显示 EMA104")
showEma156 = input.bool(false, "显示 EMA156")
showEma204 = input.bool(false, "显示 EMA204")
showDiff = input.bool(false, "显示 EMA26-EMA52 差值线?")
showCrossMarks = input.bool(false, "标记均线交叉(✕)")
// 主图 EMA
ema26 = ta.ema(src, 26)
ema52 = ta.ema(src, 52)
ema104 = ta.ema(src, 104)
ema156 = ta.ema(src, 156)
ema204 = ta.ema(src, 204)
diff = ema26 - ema52
plot(ema26, title="EMA 26", color=color.new(color.teal, 0), linewidth=2, display=showEma26 ? display.all : display.none)
plot(ema52, title="EMA 52", color=color.new(color.orange, 0), linewidth=2, display=showEma52 ? display.all : display.none)
plot(ema104, title="EMA 104", color=color.new(color.blue, 0), linewidth=2, display=showEma104 ? display.all : display.none)
plot(ema156, title="EMA 156", color=color.new(color.fuchsia, 0), linewidth=2, display=showEma156 ? display.all : display.none)
plot(ema204, title="EMA 204", color=color.new(color.green, 0), linewidth=2, display=showEma204 ? display.all : display.none)
// 交叉信号(快线上穿/下穿慢线)
crossUp = ta.crossover(ema26, ema52)
crossDn = ta.crossunder(ema26, ema52)
// 交叉点价格(取两条 EMA 的中点,视觉上就是交叉位置)
crossPrice = (ema26 + ema52) / 2.0
// 用 plotshape 标记交叉点(直接画在两条 EMA 的交叉处)
plotshape(showCrossMarks and crossUp ? crossPrice : na, title="EMA26 上穿 EMA52", style=shape.xcross, location=location.absolute, color=color.lime, size=size.small, text="", textcolor=color.lime)
plotshape(showCrossMarks and crossDn ? crossPrice : na, title="EMA26 下穿 EMA52", style=shape.xcross, location=location.absolute, color=color.red, size=size.small, text="", textcolor=color.red)