本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Soul Investor | Momentum Intelligence (EMA 21/50)", overlay=true)
// SETTINGS
fastLength = input.int(21, "Fast EMA", minval=1, group="Trend")
slowLength = input.int(50, "Slow EMA", minval=1, group="Trend")
slopeLookback = input.int(5, "Slope Lookback", minval=1, group="Trend")
emergingBars = input.int(5, "Emerging Phase Duration (Bars)", minval=1, group="Trend")
showZone = input.bool(true, "Show Momentum Zone", group="Display")
showSignals = input.bool(true, "Show Crossover Signals", group="Display")
showDashboard = input.bool(true, "Show Dashboard", group="Display")
// EMA CALCULATIONS
emaFast = ta.ema(close, fastLength)
emaSlow = ta.ema(close, slowLength)
emaSpread = emaSlow != 0 ? (emaFast / emaSlow - 1) * 100 : na
priceDistance = emaSlow != 0 ? (close / emaSlow - 1) * 100 : na
fastRising = emaFast > emaFast[slopeLookback]
slowRising = emaSlow > emaSlow[slopeLookback]
spreadGrowing = emaSpread > emaSpread[1]
spreadShrinking = emaSpread < emaSpread[1]
// CONFIRMED CROSSOVERS
bullishCross = ta.crossover(emaFast, emaSlow) and barstate.isconfirmed
bearishCross = ta.crossunder(emaFast, emaSlow) and barstate.isconfirmed
// EMERGING PHASE
barsSinceBullCross = ta.barssince(bullishCross)
emerging = emaFast > emaSlow and not na(barsSinceBullCross) and barsSinceBullCross < emergingBars
// MOMENTUM PHASES
expanding = not emerging and emaFast > emaSlow and fastRising and slowRising and spreadGrowing
cooling = not emerging and emaFast > emaSlow and spreadShrinking
negative = emaFast < emaSlow
transition = not emerging and not expanding and not cooling and not negative
// PHASE TRANSITIONS
newExpanding = expanding and not expanding[1] and barstate.isconfirmed
newCooling = cooling and not cooling[1] and barstate.isconfirmed
// PHASE COLORS
phaseColor = emerging ? color.rgb(0, 165, 165) :
expanding ? color.rgb(35, 165, 85) :
cooling ? color.rgb(210, 155, 45) :
negative ? color.rgb(195, 65, 75) :
color.gray
zoneColor = color.new(phaseColor, 85)
// EMA PLOTS
fastPlot = plot(emaFast, title="EMA 21",
color=color.rgb(0, 145, 120), linewidth=2)
slowPlot = plot(emaSlow, title="EMA 50",
color=color.rgb(65, 68, 82), linewidth=2)
fill(fastPlot, slowPlot,
color=showZone ? zoneColor : na,
title="Momentum Phase Zone")
// CROSSOVER MARKERS
plotshape(showSignals and bullishCross,
title="Bullish EMA Crossover",
style=shape.triangleup,
location=location.belowbar,
color=color.teal,
size=size.small)
plotshape(showSignals and bearishCross,
title="Bearish EMA Crossover",
style=shape.triangledown,
location=location.abovebar,
color=color.red,
size=size.small)
// DASHBOARD
var table dashboard = table.new(position.top_right, 2, 6,
bgcolor=color.rgb(48, 52, 63),
border_width=0)
if barstate.islast
if showDashboard
phaseText = emerging ? "EMERGING" :
expanding ? "EXPANDING" :
cooling ? "COOLING" :
negative ? "NEGATIVE" : "TRANSITION"
alignmentText = emaFast > emaSlow ? "POSITIVE" :
emaFast < emaSlow ? "NEGATIVE" : "NEUTRAL"
slopeText = fastRising and slowRising ? "BOTH RISING" :
not fastRising and not slowRising ? "BOTH FALLING" : "MIXED"
spreadText = na(emaSpread) ? "N/A" :
str.tostring(emaSpread, "#.##") + "%"
priceText = na(priceDistance) ? "N/A" :
str.tostring(priceDistance, "#.##") + "%"
table.cell(dashboard, 0, 0, "SOUL INVESTOR", text_color=color.white)
table.cell(dashboard, 1, 0, "MOMENTUM", text_color=color.white)
table.cell(dashboard, 0, 1, "FLOW STATUS", text_color=color.white)
table.cell(dashboard, 1, 1, phaseText, text_color=phaseColor)
table.cell(dashboard, 0, 2, "EMA ALIGNMENT", text_color=color.white)
table.cell(dashboard, 1, 2, alignmentText,
text_color=emaFast > emaSlow ? color.lime : emaFast < emaSlow ? color.red : color.silver)
table.cell(dashboard, 0, 3, "EMA SLOPE", text_color=color.white)
table.cell(dashboard, 1, 3, slopeText, text_color=color.white)
table.cell(dashboard, 0, 4, "EMA SPREAD", text_color=color.white)
table.cell(dashboard, 1, 4, spreadText, text_color=color.white)
table.cell(dashboard, 0, 5, "PRICE VS EMA 50", text_color=color.white)
table.cell(dashboard, 1, 5, priceText,
text_color=na(priceDistance) ? color.silver :
priceDistance >= 0 ? color.lime : color.red)
else
table.clear(dashboard, 0, 0, 1, 5)
// ALERTS
alertcondition(bullishCross,
title="BULLISH | EMA 21 Crosses Above EMA 50",
message="SOUL INVESTOR: {{ticker}} EMA 21 crossed ABOVE EMA 50 on {{interval}}.")
alertcondition(newExpanding,
title="EXPANDING | Momentum Strengthening",
message="SOUL INVESTOR: {{ticker}} entered EXPANDING FLOW on {{interval}}.")
alertcondition(newCooling,
title="COOLING | Momentum Weakening",
message="SOUL INVESTOR: {{ticker}} entered COOLING FLOW on {{interval}}.")
alertcondition(bearishCross,
title="BEARISH | EMA 21 Crosses Below EMA 50",
message="SOUL INVESTOR: {{ticker}} EMA 21 crossed BELOW EMA 50 on {{interval}}.")