本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Merry | Momentum Cascade", "Merry MCW", overlay = false, max_labels_count = 200)
// ══════════════════════════════════════════════════════════════════════════
// Merry — Momentum Cascade (MCW)
//
// Signature mechanism: momentum strata. Four momentum windows — 8,
// 21, 55, and 144 bars, each ATR-normalized — are stacked into a
// layered mountain: every stratum is the cumulative sum of the
// windows below it plus its own momentum, and each layer's fill is
// colored by that window's own sign. The result reads like geology:
// fast layers flip first, slow layers hold the bedrock. Alignment
// score and FLOW / SPLIT events complete the picture.
//
// Generic building blocks: multi-window momentum, ATR normalization,
// cumulative stacking. Original composition/presentation.
// © Merry. Free to use and modify.
// ══════════════════════════════════════════════════════════════════════════
// ── Inputs ────────────────────────────────────────────────────────────────
grpCore = "Core engine"
w1 = input.int(8, "Stratum 1 window", minval = 1, group = grpCore)
w2 = input.int(21, "Stratum 2 window", minval = 2, group = grpCore)
w3 = input.int(55, "Stratum 3 window", minval = 3, group = grpCore)
w4 = input.int(144, "Stratum 4 window", minval = 4, group = grpCore)
atrLn = input.int(14, "Normalizer (ATR)", minval = 1, group = grpCore)
smLen = input.int(2, "Stratum 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")
hotCol = input.color(#f7b32b, "Split", group = grpStyle)
showSig = input.bool(true, "Show event badges", group = grpStyle)
showDash = input.bool(true, "Show dashboard", group = grpStyle)
// ── Strata engine ─────────────────────────────────────────────────────────
atrN = ta.atr(atrLn)
m1 = (close - close[w1]) / (math.max(atrN, syminfo.mintick) * w1)
m2 = (close - close[w2]) / (math.max(atrN, syminfo.mintick) * w2)
m3 = (close - close[w3]) / (math.max(atrN, syminfo.mintick) * w3)
m4 = (close - close[w4]) / (math.max(atrN, syminfo.mintick) * w4)
s1 = ta.ema(m1, smLen)
s2 = ta.ema(m2, smLen)
s3 = ta.ema(m3, smLen)
s4 = ta.ema(m4, smLen)
c1 = s1
c2 = c1 + s2
c3 = c2 + s3
c4 = c3 + s4
sgn1 = s1 > 0 ? 1 : -1
sgn2 = s2 > 0 ? 1 : -1
sgn3 = s3 > 0 ? 1 : -1
sgn4 = s4 > 0 ? 1 : -1
align = (sgn1 + sgn2 + sgn3 + sgn4) / 4.0 // −1 … +1
fullFlow = math.abs(align) == 1 and math.abs(s1) + math.abs(s4) > 0.06
split = sgn1 != sgn4 and math.abs(s1) > 0.03 and math.abs(s4) > 0.03
flowNew = fullFlow and not fullFlow[1]
splitNew = split and not split[1]
// ── Rendering: momentum strata ────────────────────────────────────────────
p0 = plot(0, "Baseline", display = display.none, editable = false)
p1 = plot(c1, "Stratum 1 top", color = color.new(neutCol, 85), linewidth = 1)
p2 = plot(c2, "Stratum 2 top", color = color.new(neutCol, 85), linewidth = 1)
p3 = plot(c3, "Stratum 3 top", color = color.new(neutCol, 85), linewidth = 1)
p4 = plot(c4, "Stratum 4 top", color = color.new(neutCol, 80), linewidth = 1)
fill(p0, p1, color = color.new(sgn1 > 0 ? bullCol : bearCol, 40), title = "Stratum 1")
fill(p1, p2, color = color.new(sgn2 > 0 ? bullCol : bearCol, 60), title = "Stratum 2")
fill(p2, p3, color = color.new(sgn3 > 0 ? bullCol : bearCol, 75), title = "Stratum 3")
fill(p3, p4, color = color.new(sgn4 > 0 ? bullCol : bearCol, 86), title = "Stratum 4")
hline(0, "Zero", color = color.new(neutCol, 70), linestyle = hline.style_dotted)
bgcolor(fullFlow ? color.new(align > 0 ? bullCol : bearCol, 94) : split ? color.new(hotCol, 95) : na, title = "Alignment tint")
// Price-anchored badges
plotshape(showSig and flowNew ? c4 : na, "Full flow", shape.labelup, location.absolute, align > 0 ? bullCol : bearCol, text = "FLOW", textcolor = chart.bg_color, size = size.tiny)
plotshape(showSig and splitNew ? c4 : na, "Split", shape.labeldown, location.absolute, hotCol, text = "SPLIT", textcolor = chart.bg_color, size = size.tiny)
// Right-edge live tag
var label tag = na
if barstate.islast
label.delete(tag)
tagCol = align > 0 ? bullCol : align < 0 ? bearCol : neutCol
tag := label.new(bar_index + 2, c4, "MCW " + str.tostring(align * 100, "0") + "%", style = label.style_label_left, color = color.new(tagCol, 20), textcolor = chart.bg_color, size = size.small)
// ── Dashboard v2 ──────────────────────────────────────────────────────────
stateTxt = fullFlow ? (align > 0 ? "FULL FLOW UP" : "FULL FLOW DOWN") : split ? "FAST/SLOW SPLIT" : "MIXED"
stateCol = fullFlow ? (align > 0 ? bullCol : bearCol) : split ? hotCol : neutCol
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 · MOMENTUM CASCADE", text_color = chart.fg_color, text_size = size.tiny, bgcolor = color.new(chart.fg_color, 85))
table.cell(dash, 0, 1, "Alignment", text_color = chart.fg_color, text_size = size.small)
table.cell(dash, 1, 1, stateTxt, text_color = chart.bg_color, bgcolor = color.new(stateCol, 15), text_size = size.small)
table.cell(dash, 0, 2, "Score", text_color = chart.fg_color, text_size = size.small)
table.cell(dash, 1, 2, str.tostring(align * 100, "0") + "%", text_color = stateCol, text_size = size.small, text_halign = text.align_right)
table.cell(dash, 0, 3, "Fast × Slow", text_color = chart.fg_color, text_size = size.small)
table.cell(dash, 1, 3, (sgn1 > 0 ? "▲" : "▼") + " × " + (sgn4 > 0 ? "▲" : "▼"), text_color = sgn1 == sgn4 ? stateCol : hotCol, text_size = size.small, text_halign = text.align_right)
// ── Alerts ────────────────────────────────────────────────────────────────
alertcondition(flowNew and align > 0, "Merry MCW — full flow up", "Merry Momentum Cascade: all four strata turned positive.")
alertcondition(flowNew and align < 0, "Merry MCW — full flow down", "Merry Momentum Cascade: all four strata turned negative.")
alertcondition(splitNew, "Merry MCW — fast/slow split", "Merry Momentum Cascade: fastest and slowest strata disagree.")