本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("ETS EMA Suite", shorttitle="ETS EMA Suite", overlay=true, max_labels_count=500)
// Compact rows: checkbox/name followed by the period input.
enabled1 = input.bool(true, "EMA 1", inline="ema1", group="EMAs")
length1 = input.int(5, "Length", minval=1, inline="ema1", group="EMAs")
color1 = input.color(color.aqua, "", inline="ema1", group="EMAs", tooltip="Color for the EMA line and its label text. Change it here to keep them matched.")
enabled2 = input.bool(true, "EMA 2", inline="ema2", group="EMAs")
length2 = input.int(9, "Length", minval=1, inline="ema2", group="EMAs")
color2 = input.color(color.orange, "", inline="ema2", group="EMAs", tooltip="Color for the EMA line and its label text. Change it here to keep them matched.")
enabled3 = input.bool(true, "EMA 3", inline="ema3", group="EMAs")
length3 = input.int(21, "Length", minval=1, inline="ema3", group="EMAs")
color3 = input.color(color.lime, "", inline="ema3", group="EMAs", tooltip="Color for the EMA line and its label text. Change it here to keep them matched.")
enabled4 = input.bool(true, "EMA 4", inline="ema4", group="EMAs")
length4 = input.int(50, "Length", minval=1, inline="ema4", group="EMAs")
color4 = input.color(color.fuchsia, "", inline="ema4", group="EMAs", tooltip="Color for the EMA line and its label text. Change it here to keep them matched.")
enabled5 = input.bool(true, "EMA 5", inline="ema5", group="EMAs")
length5 = input.int(200, "Length", minval=1, inline="ema5", group="EMAs")
color5 = input.color(color.red, "", inline="ema5", group="EMAs", tooltip="Color for the EMA line and its label text. Change it here to keep them matched.")
sourceInput = input.source(close, "Source", group="General")
showLabels = input.bool(true, "Show EMA labels", group="Labels")
labelPlacement = input.string("End only", "Label placement", options=["End only", "Along lines", "Both"], group="Labels")
repeatEvery = input.int(30, "Repeat every (bars)", minval=5, maxval=500, group="Labels", tooltip="Spacing between labels along each EMA. Labels print on closed bars.")
repeatKeep = input.int(20, "Keep repeated labels per EMA", minval=1, maxval=80, group="Labels", tooltip="Keeps the most recent labels for each EMA; older labels are removed.")
endLabels = showLabels and labelPlacement != "Along lines"
alongLabels = showLabels and labelPlacement != "End only"
labelOffset = input.int(3, "End label offset (bars)", minval=0, maxval=100, group="Labels")
labelSize = input.string("Small", "Label size", options=["Tiny", "Small", "Normal", "Large"], group="Labels")
showPrice = input.bool(false, "Include EMA price", group="Labels")
textSize = switch labelSize
"Tiny" => size.tiny
"Normal" => size.normal
"Large" => size.large
=> size.small
// Shared input colors keep EMA lines and label text matched.
// Adjust colors in Inputs; line width and type remain editable in Style.
ema1 = ta.ema(sourceInput, length1)
plot(enabled1 ? ema1 : na, title="EMA 1", color=color1, linewidth=2, editable=true, linestyle=plot.linestyle_solid)
ema2 = ta.ema(sourceInput, length2)
plot(enabled2 ? ema2 : na, title="EMA 2", color=color2, linewidth=2, editable=true, linestyle=plot.linestyle_solid)
ema3 = ta.ema(sourceInput, length3)
plot(enabled3 ? ema3 : na, title="EMA 3", color=color3, linewidth=2, editable=true, linestyle=plot.linestyle_solid)
ema4 = ta.ema(sourceInput, length4)
plot(enabled4 ? ema4 : na, title="EMA 4", color=color4, linewidth=2, editable=true, linestyle=plot.linestyle_solid)
ema5 = ta.ema(sourceInput, length5)
plot(enabled5 ? ema5 : na, title="EMA 5", color=color5, linewidth=2, editable=true, linestyle=plot.linestyle_solid)
// Each call maintains one label and updates it only on the latest bar.
updateLabel(bool enabled, float value, int length, color emaColor) =>
var label tag = label.new(na, na, "", style=label.style_label_left)
if barstate.islast
if enabled and endLabels and not na(value)
string caption = str.tostring(length) + " EMA" + (showPrice ? " " + str.tostring(value, format.mintick) : "")
label.set_xy(tag, bar_index + labelOffset, value)
label.set_text(tag, caption)
label.set_color(tag, chart.bg_color)
label.set_textcolor(tag, emaColor)
label.set_size(tag, textSize)
label.set_tooltip(tag, str.tostring(length) + "-period EMA: " + str.tostring(value, format.mintick))
else
label.set_xy(tag, bar_index, na)
label.set_text(tag, "")
updateLabel(enabled1, ema1, length1, color1)
updateLabel(enabled2, ema2, length2, color2)
updateLabel(enabled3, ema3, length3, color3)
updateLabel(enabled4, ema4, length4, color4)
updateLabel(enabled5, ema5, length5, color5)
// Each written call owns its own history; cap it to protect the five end labels.
repeatLabel(bool enabled, float value, int length, color emaColor) =>
var array<label> history = array.new<label>()
if enabled and alongLabels and barstate.isconfirmed and bar_index % repeatEvery == 0 and not na(value)
string caption = str.tostring(length) + " EMA" + (showPrice ? " " + str.tostring(value, format.mintick) : "")
label marker = label.new(bar_index, value, caption, xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_center, color=chart.bg_color, textcolor=emaColor, size=textSize, tooltip=str.tostring(length) + "-period EMA: " + str.tostring(value, format.mintick))
array.push(history, marker)
if array.size(history) > repeatKeep
label.delete(array.shift(history))
repeatLabel(enabled1, ema1, length1, color1)
repeatLabel(enabled2, ema2, length2, color2)
repeatLabel(enabled3, ema3, length3, color3)
repeatLabel(enabled4, ema4, length4, color4)
repeatLabel(enabled5, ema5, length5, color5)