PROTECTED SOURCE SCRIPT

Ultimate Market Sentiment (UMS)

56
Ultimate Market Sentiment (UMS) — Multi-Factor Quantitative Sentiment Oscillator
A institutional-grade sentiment indicator synthesizing five distinct market dimensions—trend momentum, volatility regime, relative strength, volume-pressure, and hidden Markov states—into a unified [-100, +100] sentiment gauge using robust statistical normalization and sigmoid compression.
Overview
The Ultimate Market Sentiment (UMS) indicator represents a comprehensive quantitative approach to market psychology, combining orthogonal data sources into a single interpretable sentiment score. Unlike simple oscillators that rely on price alone, UMS integrates trend dynamics, fear gauges (volatility), benchmark-relative performance, institutional flow (volume-weighted returns), and probabilistic regime detection via Hidden Markov Models. Each component undergoes robust Z-score normalization and sigmoid compression to ensure comparable scale and saturation behavior, then weighted-combined into a final sentiment reading ranging from -100 (extreme panic) to +100 (extreme euphoria).

Key Features
  • Five-Factor Sentiment Model: Combines Trend, Volatility (inverted fear), Relative Strength, Volume Flow, and HMM Regime probability into composite sentiment
  • Hidden Markov Model (HMM) Regime Detection: Probabilistic 2-state model (Bull/Bear) with configurable transition probabilities and regime-specific return distributions (μ, σ)
  • Robust Z-Score Normalization: Manual statistical implementation handling NA values, with variance clamping and population standard deviation calculation over configurable windows
  • Sigmoid Compression: Maps extreme Z-scores to bounded [-1, 1] range using logistic function with adjustable sensitivity (temperature) parameter
  • Custom Logarithmic Implementation: Series-expansion based natural log calculation for return computations, avoiding built-in function dependencies
  • Least-Squares Trend Extraction: Linear regression slope calculation via normal equations for true mathematical trend measurement (not just price differences)
  • Benchmark Relative Analysis: Optional comparison against external symbol (default SPY) for alpha-generation measurement
  • Adaptive Weighting System: Automatic weight renormalization when components are disabled, ensuring valid probability distributions
  • Extreme Zone Detection: Visual markers and background coloring for Euphoria (>60) and Panic (<-60) thresholds


The Five Sentiment Components
1. Trend Component (Momentum)
Calculates the slope of the log-price curve using least-squares linear regression over the Trend slope window. The slope represents instantaneous trend momentum—positive values indicate upward drift, negative indicate downward. This is Z-scored against historical trend slopes and compressed via sigmoid to [-1, 1], creating a momentum sentiment gauge that saturates during parabolic trends.
2. Volatility Component (Fear/Stress)
Measures realized volatility (standard deviation of log returns) over the Volatility window. High volatility typically coincides with market fear and uncertainty. The component is inverted (-1 × sigmoid(Z)) so that high volatility produces negative sentiment (bearish/fear) and low volatility produces positive sentiment (calm/confidence). This captures the "fear gauge" dimension of market psychology.
3. Relative Strength Component (Alpha)
Compares cumulative log returns of the asset versus a benchmark symbol (e.g., SPY) over the Relative strength window. Positive values indicate the asset is outperforming the market (relative strength), negative indicates underperformance. This isolates idiosyncratic sentiment specific to the instrument versus broad market beta. Can be disabled for forex/crypto where benchmark selection is ambiguous.
4. Volume Flow Component (Institutional Pressure)
Calculates return × relative volume, where relative volume is current volume divided by average volume. This measures the "conviction" behind price moves—large moves on high volume generate extreme sentiment values, while quiet moves generate muted signals. Captures institutional accumulation/distribution pressure.
5. Regime Component (HMM State Probability)
Implements a 2-state Hidden Markov Model with Bull and Bear regimes, each characterized by mean return (μ) and volatility (σ). The model calculates the posterior probability of being in the Bull regime given observed returns, using Bayesian updating with configurable transition probabilities (P(stay in bull) and P(stay in bear)). Output is scaled from [0, 1] probability to [-1, 1] sentiment (2×(P-0.5)). Provides the "smart money" regime context.
How It Works
Normalization Pipeline
Each component follows a rigorous statistical pipeline:
  • Raw calculation (slope, volatility, return difference, etc.)
  • Robust Z-score: (Value - Mean) / StdDev calculated over Normalization window
  • Sigmoid compression: 2/(1+e^(-Z/sens)) - 1 mapping to [-1, 1] with adjustable sensitivity
  • Weighting: Multiplied by user-defined weights (default: Trend 30%, Volatility 25%, RS 20%, Flow 15%, Regime 10%)

Composite Construction
Weighted components are summed and then re-normalized via Z-score and sigmoid compression to prevent any single extreme component from dominating the final output. Final scaling to [-100, 100] provides intuitive interpretation.
Hidden Markov Model Mechanics
The HMM assumes the market exists in unobserved Bull or Bear states with Gaussian return distributions:
  • Bull regime: Mean μ_bull (default +0.05%/bar), StdDev σ_bull (default 1.0%)
  • Bear regime: Mean μ_bear (default -0.05%/bar), StdDev σ_bear (default 1.5%)
  • Transition matrix: High persistence probabilities (default 97% chance of staying in current state)
  • Bayesian updating: Calculates P(Bull|Return) using prior probability and likelihood functions

Settings Guide
  • Trend slope window: Lookback for linear regression trend calculation (default 50). Longer = smoother trend, shorter = more responsive.
  • Relative strength window: Cumulative return comparison period (default 50). Synchronize with typical holding periods.
  • Realized volatility window: Standard deviation calculation period (default 20). Standard monthly volatility window.
  • Volume flow window: Volume averaging period (default 20).
  • Z-score normalization window: Statistical baseline for all Z-scores (default 200). Longer windows provide more stable percentiles but slower adaptation to regime changes.
  • Z-score compression (sensitivity): Sigmoid temperature parameter (default 2.0). Higher values (5-10) create smoother, slower-saturating sentiment; lower values (0.5-1.0) create binary-like sharp transitions.
  • Benchmark symbol: Default SPY for equities; change to QQQ, IWM, or disable for non-equity assets.
  • HMM Parameters:
  • Bull/Bear regime means: Expected returns per bar in each state (adjust for timeframe—daily vs hourly)
  • Standard deviations: Volatility characteristics of each regime (bears typically higher vol)
  • P(stay): Regime persistence (0.97 = slow transitions, 0.8 = faster regime detection)
  • Lime: Trend component
  • Orange: Volatility (inverted) component
  • Blue: Relative Strength component
  • Purple: Volume Flow component
  • Fuchsia: Regime probability component
  • Background Coloring: Green tint in bullish zones (>20), red tint in bearish zones (<-20), intensifying beyond ±60
  • Signal Markers: Triangles marking crossovers into Euphoria (▲ green) and Panic (▼ red) zones


Interpret UMS as a contrarian indicator when extremes persist (>60 or <-60) and as a trend-confirmation tool during intermediate zones. Divergences between UMS and price (e.g., price making new lows but UMS forming higher lows) often signal impending reversals. The individual component plots reveal which factors are driving sentiment—if Trend is bullish but Volatility is deeply negative, the market may be experiencing a "wall of worry" climb. When all five components align (all positive or all negative), the signal carries maximum conviction.

免責事項

この情報および投稿は、TradingViewが提供または推奨する金融、投資、トレード、その他のアドバイスや推奨を意図するものではなく、それらを構成するものでもありません。詳細は利用規約をご覧ください。