本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Merry | Confluence Trend Score", "Merry CTS", overlay = false, max_labels_count = 200)
// ══════════════════════════════════════════════════════════════════════════
// Merry — Confluence Trend Score (CTS)
//
// Five independent trend checks — price vs base EMA, DI dominance,
// EMA stack, 10-bar momentum, and regression slope — each worth 20
// points, summed into a 0–100 confluence score and smoothed. Rendered
// as a gradient pillar stream with a glowing score core; strong zones
// tint the pane. Zone entries print as price-anchored badges and the
// dashboard reports score, regime, and the live check readout.
//
// Generic building blocks: EMA, DMI, momentum, linear regression.
// Original composition/presentation. © Merry. Free to use and modify.
// ══════════════════════════════════════════════════════════════════════════
// ── Inputs ────────────────────────────────────────────────────────────────
grpCore = "Core engine"
lenSl = input.int(50, "Base EMA", minval = 2, group = grpCore)
lenFs = input.int(20, "Stack fast EMA", minval = 2, group = grpCore)
momN = input.int(10, "Momentum lookback", minval = 1, group = grpCore)
regN = input.int(20, "Slope window", minval = 2, group = grpCore)
diLen = input.int(14, "DI length", minval = 1, group = grpCore)
adxLn = input.int(14, "DI smoothing", minval = 1, group = grpCore)
grpStyle = "Style"
bullCol = input.color(#089981, "Bull", group = grpStyle, inline = "c1")
bearCol = input.color(#f23645, "Bear", group = grpStyle, inline = "c1")
neutCol = input.color(#787b86, "Neutral", group = grpStyle, inline = "c1")
showSig = input.bool(true, "Show zone badges", group = grpStyle)
showDash = input.bool(true, "Show dashboard", group = grpStyle)
// ── Five checks ───────────────────────────────────────────────────────────
eSl = ta.ema(close, lenSl)
eFs = ta.ema(close, lenFs)
[diP, diM, adxV] = ta.dmi(diLen, adxLn)
c1 = close > eSl
c2 = diP > diM
c3 = eFs > eSl
c4 = close > close[momN]
c5 = ta.linreg(close, regN, 0) > ta.linreg(close, regN, 1)
raw = ((c1 ? 1 : 0) + (c2 ? 1 : 0) + (c3 ? 1 : 0) + (c4 ? 1 : 0) + (c5 ? 1 : 0)) * 20.0
score = ta.ema(raw, 3)
// ── Rendering ─────────────────────────────────────────────────────────────
scoreCol = color.from_gradient(score, 0.0, 100.0, bearCol, bullCol)
bgcolor(score >= 70 ? color.new(bullCol, 92) : score <= 30 ? color.new(bearCol, 92) : na, title = "Strong-zone tint")
plot(score, "Score pillars", style = plot.style_columns, color = color.new(scoreCol, 55))
plot(score, "Score glow", color = color.new(scoreCol, 80), linewidth = 4)
plot(score, "Score core", color = scoreCol, linewidth = 1)
hline(70, "Bull strong", color = color.new(bullCol, 40), linestyle = hline.style_dashed)
hline(30, "Bear strong", color = color.new(bearCol, 40), linestyle = hline.style_dashed)
hline(50, "Center", color = color.new(neutCol, 60), linestyle = hline.style_dotted)
// Price-anchored zone-entry badges
plotshape(showSig and ta.crossover(score, 70) ? score : na, "Bull strong", shape.labelup, location.absolute, bullCol, text = "70", textcolor = chart.bg_color, size = size.tiny)
plotshape(showSig and ta.crossunder(score, 30) ? score : na, "Bear strong", shape.labeldown, location.absolute, bearCol, text = "30", textcolor = chart.bg_color, size = size.tiny)
// Right-edge live score tag
var label tag = na
if barstate.islast
label.delete(tag)
tag := label.new(bar_index + 2, score, str.tostring(score, "0") + "/100", style = label.style_label_left, color = color.new(scoreCol, 20), textcolor = chart.bg_color, size = size.small)
// ── Dashboard v2 ──────────────────────────────────────────────────────────
regimeTxt = score >= 70 ? "BULL STRONG" : score <= 30 ? "BEAR STRONG" : "MIXED"
regimeCol = score >= 70 ? bullCol : score <= 30 ? bearCol : neutCol
checksTxt = (c1 ? "1" : "0") + (c2 ? "1" : "0") + (c3 ? "1" : "0") + (c4 ? "1" : "0") + (c5 ? "1" : "0")
var table dash = table.new(position.top_right, 2, 4, border_width = 0, frame_width = 1, frame_color = color.new(chart.fg_color, 75), bgcolor = color.new(chart.fg_color, 92))
if showDash and barstate.islast
table.merge_cells(dash, 0, 0, 1, 0)
table.cell(dash, 0, 0, "MERRY · CONFLUENCE SCORE", text_color = chart.fg_color, text_size = size.tiny, bgcolor = color.new(chart.fg_color, 85))
table.cell(dash, 0, 1, "Score", text_color = chart.fg_color, text_size = size.small)
table.cell(dash, 1, 1, str.tostring(score, "0") + "/100", text_color = chart.bg_color, bgcolor = color.new(scoreCol, 15), text_size = size.small, text_halign = text.align_right)
table.cell(dash, 0, 2, "Regime", text_color = chart.fg_color, text_size = size.small)
table.cell(dash, 1, 2, regimeTxt, text_color = chart.bg_color, bgcolor = color.new(regimeCol, 15), text_size = size.small)
table.cell(dash, 0, 3, "Checks", text_color = chart.fg_color, text_size = size.small)
table.cell(dash, 1, 3, checksTxt, text_color = neutCol, text_size = size.small, text_halign = text.align_right)
// ── Alerts ────────────────────────────────────────────────────────────────
alertcondition(ta.crossover(score, 70), "Merry CTS — bull strong", "Merry Confluence Trend Score: score crossed above 70.")
alertcondition(ta.crossunder(score, 30), "Merry CTS — bear strong", "Merry Confluence Trend Score: score crossed below 30.")
alertcondition(ta.crossunder(score, 50) or ta.crossover(score, 50), "Merry CTS — center flip", "Merry Confluence Trend Score: score crossed the 50 center.")