39 lines
1.4 KiB
Plaintext
39 lines
1.4 KiB
Plaintext
//@version=6
|
|
indicator("EMA26-EMA52 差值线", shorttitle="EMA26_52_DIFF", overlay=false, max_labels_count=500)
|
|
|
|
// 参数
|
|
src = input.source(close, "价格源")
|
|
lenFast = input.int(26, "快线 EMA 长度", minval=1)
|
|
lenSlow = input.int(52, "慢线 EMA 长度", minval=1)
|
|
showCrossMarks = input.bool(true, "标记均线交叉(✕)")
|
|
|
|
// 计算 EMA 与差值
|
|
emaFast = ta.ema(src, lenFast)
|
|
emaSlow = ta.ema(src, lenSlow)
|
|
diff = emaFast - emaSlow
|
|
|
|
// 交叉信号(快线上穿/下穿慢线)
|
|
crossUp = ta.crossover(emaFast, emaSlow)
|
|
crossDn = ta.crossunder(emaFast, emaSlow)
|
|
|
|
// 在差值线上标记交叉点(在本窗格显示)
|
|
if showCrossMarks and crossUp
|
|
label.new(bar_index, diff, "✕", xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_center, color=color.new(color.black, 100), textcolor=color.lime, size=size.small)
|
|
if showCrossMarks and crossDn
|
|
label.new(bar_index, diff, "✕", xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_center, color=color.new(color.black, 100), textcolor=color.red, size=size.small)
|
|
|
|
// 零轴
|
|
plot(
|
|
0,
|
|
title = "零轴",
|
|
color = color.new(color.gray, 70),
|
|
linewidth = 1
|
|
)
|
|
|
|
// 差值线(类似 MACD 的 DIF 线)
|
|
plot(
|
|
diff,
|
|
title = "EMA26 - EMA52 差值",
|
|
color = diff >= 0 ? color.new(color.teal, 0) : color.new(color.red, 0),
|
|
linewidth = 2
|
|
) |