本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("InvestMode | Structural Squeeze & Momentum Engine v6", overlay=false)
// =============================================================================
// ENGINE 1: VOLATILITY COMPRESSION (BOLLINGER / KELTNER SQUEEZE)
// =============================================================================
int length = input.int(20, title="Squeeze Evaluation Period")
float bbMult = input.float(2.0, title="Bollinger Band Multiplier")
float kcMult = input.float(1.5, title="Keltner Channel Multiplier")
float basis = ta.sma(close, length)
float dev = ta.stdev(close, length)
// Calculate Bollinger Bands
float bbUpper = basis + (dev * bbMult)
float bbLower = basis - (dev * bbMult)
// Calculate Keltner Channels using explicit v6 ta.tr(true) compiler syntax
float ma = ta.sma(close, length)
float rangeValue = ta.tr(true)
float rangema = ta.sma(rangeValue, length)
float kcUpper = ma + (rangema * kcMult)
float kcLower = ma - (rangema * kcMult)
// Squeeze Condition: When Bollinger Bands contract inside Keltner Channels
bool isSqueezed = (bbUpper < kcUpper) and (bbLower > kcLower)
// =============================================================================
// ENGINE 2: MOMENTUM RELEASE VECTOR (LINEAR REGRESSION)
// =============================================================================
float highestHigh = ta.highest(high, length)
float lowestLow = ta.lowest(low, length)
float smaClose = ta.sma(close, length)
float momentumHist = ta.linreg(close - (highestHigh + lowestLow) / 2.0 + smaClose, length, 0)
// =============================================================================
// ENGINE 3: VISUALIZATION & COLOR NAMESPACES
// =============================================================================
// Plot the Squeeze Condition Dot Line (Red = Compressing, Green = Released)
color dotColor = isSqueezed ? color.red : color.green
plot(0, title="Squeeze Dot Indicator", color=dotColor, style=plot.style_circles, linewidth=3)
// Calculate dynamic histogram colors for multi-day strength monitoring
float prevMomentumHist = nz(momentumHist[1])
color histColor = momentumHist > 0 ? (momentumHist > prevMomentumHist ? color.lime : color.green) : (momentumHist < prevMomentumHist ? color.maroon : color.red)
plot(momentumHist, title="Momentum Histogram", color=histColor, style=plot.style_histogram, linewidth=4)
// =============================================================================
// AUTOMATED COMPLIANT ALERT STRINGS (FIXED V6 COMPILER BOOTSTRAP)
// =============================================================================
// Comparing directly to true converts a nullable boolean series into a strict bool loop
bool wasSqueezed = isSqueezed[1] == true
bool squeezeRelease = (isSqueezed == false) and wasSqueezed
if squeezeRelease
alert("InvestMode Alert: Structural Squeeze Release Detected. High-velocity multi-day swing move imminent.", alert.freq_once_per_bar_close)