INVITE-ONLY SCRIPT

MA (5 lines with labels)

21
//version=5
indicator(title="Multi MA (5 lines with labels)", shorttitle="5MA", overlay=true)

// === 参数设置 ===
show_prices = input.bool(true, "显示价格标签")
distance = input.int(2, "标签距离")

ma1_enable = input.bool(true, "启用 MA1")
ma1_len = input.int(9, "MA1 周期")
ma1_color = input.color(color.red, "MA1 颜色")

ma2_enable = input.bool(true, "启用 MA2")
ma2_len = input.int(50, "MA2 周期")
ma2_color = input.color(color.green, "MA2 颜色")

ma3_enable = input.bool(true, "启用 MA3")
ma3_len = input.int(100, "MA3 周期")
ma3_color = input.color(color.blue, "MA3 颜色")

ma4_enable = input.bool(true, "启用 MA4")
ma4_len = input.int(150, "MA4 周期")
ma4_color = input.color(color.orange, "MA4 颜色")

ma5_enable = input.bool(true, "启用 MA5")
ma5_len = input.int(200, "MA5 周期")
ma5_color = input.color(color.black, "MA5 颜色")

// === 计算 MA ===
ma1 = ma1_enable ? ta.sma(close, ma1_len) : na
ma2 = ma2_enable ? ta.sma(close, ma2_len) : na
ma3 = ma3_enable ? ta.sma(close, ma3_len) : na
ma4 = ma4_enable ? ta.sma(close, ma4_len) : na
ma5 = ma5_enable ? ta.sma(close, ma5_len) : na

// === 绘制线条 ===
plot(ma1, title="MA1", color=ma1_color, linewidth=2)
plot(ma2, title="MA2", color=ma2_color, linewidth=2)
plot(ma3, title="MA3", color=ma3_color, linewidth=2)
plot(ma4, title="MA4", color=ma4_color, linewidth=2)
plot(ma5, title="MA5", color=ma5_color, linewidth=2)

// === 绘制右侧价格标签 ===
label_dist = time + math.round(ta.change(time) * distance)

make_label(_val, _len, _color) =>
if not na(_val)
txt = show_prices ? "MA " + str.tostring(_len) + " - " + str.tostring(math.round_to_mintick(_val)) : "MA " + str.tostring(_len)
label.new(label_dist, _val, text=txt, xloc=xloc.bar_time, color=_color, textcolor=_color, style=label.style_none, size=size.normal)

if barstate.islast
make_label(ma1, ma1_len, ma1_color)
make_label(ma2, ma2_len, ma2_color)
make_label(ma3, ma3_len, ma3_color)
make_label(ma4, ma4_len, ma4_color)
make_label(ma5, ma5_len, ma5_color)

Haftungsausschluss

Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.