本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
// © Mishundare | IntelligenceFlow
// Successor of "Wolfpack id @Mishu" (2021), fully rewritten.
indicator("Momentum Pulse [@Mishu]", shorttitle = "MPulse", overlay = false)
// ───── Inputs ─────
grpM = "Pulse"
fastLen = input.int(3, "Fast length", minval = 1, group = grpM)
slowLen = input.int(8, "Slow length", minval = 2, group = grpM)
sigLen = input.int(21, "Signal length", minval = 1, group = grpM)
maType = input.string("EMA", "MA type", options = ["EMA", "SMA"], group = grpM)
normalize = input.bool(true, "Normalize by ATR", group = grpM, tooltip = "Divides the pulse by the ATR. Values become comparable across symbols and timeframes (1.0 = one ATR).")
atrLen = input.int(14, "ATR length", minval = 1, group = grpM)
deadZone = input.float(0.05, "Dead zone (±)", minval = 0.0, step = 0.01, group = grpM, tooltip = "Zero-line crosses inside ± this value are ignored to reduce whipsaws. With ATR normalization 0.05 = 5% of one ATR.")
grpF = "Higher-timeframe filter"
useHtf = input.bool(false, "Use filter", group = grpF, tooltip = "Crosses are only marked when the pulse on the filter timeframe points the same way. Uses the last closed higher-timeframe bar (no repainting).")
htfTf = input.timeframe("60", "Filter timeframe", group = grpF)
grpV = "Display"
showHist = input.bool(true, "Histogram", group = grpV)
showSignal = input.bool(false, "Signal line", group = grpV)
showMarks = input.bool(true, "Cross markers", group = grpV)
showHtfBg = input.bool(true, "Background = filter direction", group = grpV)
colBull = input.color(#26a69a, "Bullish", group = grpV)
colBear = input.color(#ef5350, "Bearish", group = grpV)
// ───── Calculation ─────
ma(float src, int len) =>
e = ta.ema(src, len)
s = ta.sma(src, len)
maType == "EMA" ? e : s
pulseCalc() =>
raw = ma(close, fastLen) - ma(close, slowLen)
a = ta.atr(atrLen)
normalize ? raw / a : raw
pulse = pulseCalc()
signal = ta.ema(pulse, sigLen)
hist = pulse - signal
// Last CLOSED bar of the filter timeframe -> values never change afterwards
htfVal = request.security(syminfo.tickerid, htfTf, pulseCalc()[1], lookahead = barmerge.lookahead_on)
htfBull = not useHtf or htfVal > 0
htfBear = not useHtf or htfVal < 0
crossUp = ta.crossover(pulse, deadZone) and htfBull and barstate.isconfirmed
crossDn = ta.crossunder(pulse, -deadZone) and htfBear and barstate.isconfirmed
// ───── Plots ─────
histCol = hist >= 0 ? (hist > hist[1] ? #26a69a : #b2dfdb) : (hist < hist[1] ? #ef5350 : #ffcdd2)
plot(showHist ? hist : na, "Histogram", histCol, style = plot.style_columns)
pulseCol = pulse > deadZone ? colBull : pulse < -deadZone ? colBear : color.gray
plot(pulse, "Pulse", pulseCol, 2)
plot(showSignal ? signal : na, "Signal", color.orange)
hline(0, "Zero line", color.new(color.gray, 40), hline.style_dotted)
plot(deadZone > 0 ? deadZone : na, "Dead zone +", color.new(color.gray, 70), style = plot.style_line)
plot(deadZone > 0 ? -deadZone : na, "Dead zone −", color.new(color.gray, 70), style = plot.style_line)
plotshape(showMarks and crossUp, "Bullish cross", shape.circle, location.bottom, colBull, size = size.tiny)
plotshape(showMarks and crossDn, "Bearish cross", shape.circle, location.top, colBear, size = size.tiny)
bgcolor(useHtf and showHtfBg ? (htfVal > 0 ? color.new(colBull, 92) : color.new(colBear, 92)) : na)
// ───── Alerts ─────
alertcondition(crossUp, "Bullish cross", "MPulse: bullish zero-line cross on {{ticker}} ({{interval}})")
alertcondition(crossDn, "Bearish cross", "MPulse: bearish zero-line cross on {{ticker}} ({{interval}})")
alertcondition(crossUp or crossDn, "Any cross", "MPulse: zero-line cross on {{ticker}} ({{interval}})")
if crossUp
alert("MPulse bullish cross | " + syminfo.ticker + " | " + timeframe.period, alert.freq_once_per_bar_close)
if crossDn
alert("MPulse bearish cross | " + syminfo.ticker + " | " + timeframe.period, alert.freq_once_per_bar_close)