OPEN-SOURCE SCRIPT

Relative Valuation Oscillator [QuantAlgo]

299
🟢 Overview

The Relative Valuation Oscillator identifies statistical price deviations from fair value using logarithmic price analysis and standard deviation bands. It calculates how far current price has deviated from its mean on a logarithmic scale, normalized by volatility, to generate a centered oscillator that highlights periods when price is statistically stretched above or below its historical average, helping traders identify potential mean reversion opportunities and extreme valuation conditions across different timeframes and markets.
snapshot
🟢 How It Works

The indicator's core methodology lies in its statistical approach to price valuation, where deviations are measured using logarithmic returns and normalized by standard deviation:
Pine Script®
log_price = math.log(close) mean_log_price = ta.sma(log_price, lookback_period) standard_deviation = ta.stdev(log_price, lookback_period) valuation_score = (log_price - mean_log_price) / standard_deviation

First, the script converts price to logarithmic form to account for percentage-based price movements rather than absolute dollar changes, ensuring the indicator works consistently across different price levels and asset classes.

Then, it calculates the mean log price over the specified lookback period to establish a baseline fair value reference:
Pine Script®
mean_log_price = ta.sma(log_price, lookback_period)

Next, standard deviation measurement quantifies the typical volatility of log price around this mean, providing a statistical framework for defining normal versus extreme price behavior:
Pine Script®
standard_deviation = ta.stdev(log_price, lookback_period)

The valuation score is then derived by measuring how many standard deviations the current log price sits from its mean, creating a normalized oscillator that fluctuates around zero:
Pine Script®
valuation_score = (log_price - mean_log_price) / standard_deviation

Finally, threshold-based signal detection identifies extreme conditions when the valuation score exceeds user-defined standard deviation multiples:
Pine Script®
is_overvalued = valuation_score > threshold_mult is_undervalued = valuation_score < -threshold_mult

This creates a statistical mean reversion system that identifies when price has deviated significantly from its historical average on a volatility-adjusted basis, providing traders with objective measurements of relative over or undervaluation.
snapshot
🟢 Signal Interpretation

▶ Undervalued Zone (Below Negative Threshold): Oscillator falling below the negative threshold line indicates price has deviated significantly below its statistical mean = Potential long/buy opportunities for mean reversion strategies

▶ Overvalued Zone (Above Positive Threshold): Oscillator rising above the positive threshold line indicates price has deviated significantly above its statistical mean = Potential short/sell or profit-taking opportunities
snapshot
▶ Fair Value Range (Between Thresholds): Oscillator remaining between positive and negative threshold lines indicates price is trading within normal statistical bounds. Within this range, the zero line acts as a directional filter: oscillator above zero but below the upper threshold suggests bullish trend/momentum with price trading above its statistical mean = Trend-following long positions can be maintained; oscillator below zero but above the lower threshold suggests bearish trend/momentum with price trading below its statistical mean = Trend-following short positions can be maintained. The oscillator can remain in these directional zones during sustained trends until mean reversion occurs, signaled by crosses back toward zero or transitions to the opposite extreme threshold.
snapshot
▶ Zero Line Crosses: Oscillator crossing above zero indicates transition from below-average to above-average valuation, confirming shift to bullish momentum = Potential trend-following long entry; crossing below zero indicates transition from above-average to below-average valuation, confirming shift to bearish momentum = Potential trend-following short entry or long exit. These crosses can signal both the start of directional trends and early mean reversion from extreme conditions.

🟢 Features

▶ Preconfigured Presets: Three optimized parameter sets for different trading approaches and timeframes. "Default" provides balanced sensitivity for swing trading on 4-hour and daily charts, generating signals at statistically significant deviations. "Fast Response" delivers more frequent signals for intraday trading on 5-minute to 1-hour charts, reacting quickly to short-term deviations with increased signal frequency. "Smooth Trend" focuses on major extremes for position trading on daily to weekly timeframes, filtering noise to identify only the most significant statistical outliers.
snapshot
▶ Built-in Alerts: Five alert conditions enable automated monitoring of valuation extremes and transitions. "Overvalued Threshold Crossed" triggers when the oscillator crosses above the positive threshold, signaling potential overvaluation. "Undervalued Threshold Crossed" activates when the oscillator crosses below the negative threshold, signaling potential undervaluation. "Crossed Above Fair Value (0)" and "Crossed Below Fair Value (0)" provide alerts for zero line transitions, indicating shifts between above-average and below-average valuation. "Any Extreme Valuation" offers a combined alert for any threshold breach regardless of direction, allowing traders to monitor both extremes with a single alert setup.
snapshot
▶ Color Customization: Six visual themes (Classic, Aqua, Cosmic, Cyber, Neon, plus Custom) accommodate different chart backgrounds and visual preferences, with distinct colors for overvalued, undervalued, and fair value conditions. Optional background highlighting with adjustable transparency (0-100%) tints the main chart background during extreme valuation periods, providing immediate visual context without requiring continuous oscillator monitoring. Optional overlay signals display small circle markers directly on the price chart above bars during overvaluation and below bars during undervaluation, allowing correlation of statistical extremes with specific price levels and candlestick patterns.
snapshot

Wyłączenie odpowiedzialności

Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.