本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Momentum Flow Oscillator", shorttitle="MFO", overlay=false)
//────────────────────────────────────────────
// INPUTS
//────────────────────────────────────────────
groupMomentum = "Momentum"
momentumLength = input.int(14, "Momentum Length", minval=2, group=groupMomentum)
rsiLength = input.int(14, "RSI Length", minval=2, group=groupMomentum)
groupTrend = "Trend Pressure"
emaLength = input.int(34, "Trend EMA Length", minval=2, group=groupTrend)
groupSmoothing = "Smoothing"
smoothLength = input.int(5, "Smoothing Length", minval=1, group=groupSmoothing)
groupLevels = "Levels"
overbought = input.float(60.0, "Upper Level", group=groupLevels)
oversold = input.float(-60.0, "Lower Level", group=groupLevels)
//────────────────────────────────────────────
// MOMENTUM COMPONENT
//────────────────────────────────────────────
priceChange = close - close[momentumLength]
atrValue = ta.atr(momentumLength)
normalizedMomentum = atrValue != 0 ? (priceChange / atrValue) * 20.0 : 0.0
momentumComponent = math.max(-100.0, math.min(100.0, normalizedMomentum))
//────────────────────────────────────────────
// RSI COMPONENT
//────────────────────────────────────────────
rsiValue = ta.rsi(close, rsiLength)
rsiComponent = (rsiValue - 50.0) * 2.0
//────────────────────────────────────────────
// TREND PRESSURE COMPONENT
//────────────────────────────────────────────
trendEma = ta.ema(close, emaLength)
trendDistance = atrValue != 0 ? ((close - trendEma) / atrValue) * 30.0 : 0.0
trendComponent = math.max(-100.0, math.min(100.0, trendDistance))
//────────────────────────────────────────────
// COMPOSITE OSCILLATOR
//────────────────────────────────────────────
rawOscillator = momentumComponent * 0.40 + rsiComponent * 0.35 + trendComponent * 0.25
oscillator = ta.ema(rawOscillator, smoothLength)
signal = ta.ema(oscillator, smoothLength)
histogram = oscillator - signal
//────────────────────────────────────────────
// MOMENTUM STATE
//────────────────────────────────────────────
bullishMomentum = oscillator > 0
bearishMomentum = oscillator < 0
bullishShift = ta.crossover(oscillator, signal)
bearishShift = ta.crossunder(oscillator, signal)
//────────────────────────────────────────────
// REFERENCE LEVELS
//────────────────────────────────────────────
hline(0, "Zero Line", color=color.gray)
hline(overbought, "Upper Level", color=color.red, linestyle=hline.style_dashed)
hline(oversold, "Lower Level", color=color.green, linestyle=hline.style_dashed)
//────────────────────────────────────────────
// HISTOGRAM
//────────────────────────────────────────────
histColor = histogram >= 0 ? (histogram > histogram[1] ? color.lime : color.green) : (histogram < histogram[1] ? color.red : color.orange)
plot(
histogram,
title="Momentum Histogram",
style=plot.style_columns,
color=histColor
)
//────────────────────────────────────────────
// OSCILLATOR LINE
//────────────────────────────────────────────
oscColor = oscillator >= 0 ? color.aqua : color.orange
plot(
oscillator,
title="Momentum Flow",
color=oscColor,
linewidth=2
)
//────────────────────────────────────────────
// SIGNAL LINE
//────────────────────────────────────────────
plot(
signal,
title="Signal",
color=color.yellow,
linewidth=1
)
//────────────────────────────────────────────
// MOMENTUM SHIFT MARKERS
//────────────────────────────────────────────
plotshape(
bullishShift,
title="Bullish Momentum Shift",
style=shape.triangleup,
location=location.bottom,
color=color.lime,
size=size.tiny
)
plotshape(
bearishShift,
title="Bearish Momentum Shift",
style=shape.triangledown,
location=location.top,
color=color.red,
size=size.tiny
)
//────────────────────────────────────────────
// ALERTS
//────────────────────────────────────────────
alertcondition(
bullishShift,
title="Bullish Momentum Shift",
message="Vertex Momentum Flow Oscillator: Bullish momentum shift detected."
)
alertcondition(
bearishShift,
title="Bearish Momentum Shift",
message="Vertex Momentum Flow Oscillator: Bearish momentum shift detected."
)