Indicator · Pine Script v4 · Own pane

SPX Sentiment

by nvFede· code credited to QuantStreet

A Pine v4 indicator in a separate pane that divides the S&P 500 index by the VIX volatility index to form a ratio, then compares it with its own average and a z-score style measure over a chosen length.

View on GitHub

GitHub stars1on the repository
Pine versionv4older, still runs
Lines of code51
Settings7inputs
LicenceNone statedfile: MPL-2.0
Last update3 years ago19 Mar 2023

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

51 lines of Pine Script v4 from TradingView_old/2022/SPX_Sentiment.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

SPX_Sentiment.pine
//@version=4
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © QuantStreet

study("SPX Sentiment", shorttitle="SPX Sentiment")
length = input(50)

vix_close = security("VIX", timeframe.period, close)
spx_close = security("SPX", timeframe.period, close)

smoothness = input(title="Smoothnees", defval=3, minval=0)

mean_line = input(title="Mean Length", defval=100, minval=0)

ratio = spx_close / vix_close

bg_sma = sma(ratio, 200)
bg_color = ratio > bg_sma ? color.green : color.red

calc_zvwap(pds) =>
    mean = wma(ratio, length)
    vwapsd = sqrt(sma(pow(ratio - mean, 2), pds))
    (ratio - mean) / vwapsd



plot(0)
upperTop = input(5) * 10
upperBottom = input(5.0) * 10
lowerTop = input(-5) * 10
lowerBottom = input(-5.0) * 10

line_color = color.black

//plot(10, style=hline.style_dashed, color=color.gray)
//plot(-10, style=hline.style_dashed, color=color.gray)


cg = change(close, 1)


zwap = ema(calc_zvwap(length), smoothness) * 20

zwap_correlation = correlation(zwap, close, 10) * 20

plot(correlation(sma(cg,10), zwap, 10) * 10, color=color.yellow)

//plot(zwap_correlation, color=black, linewidth=2)
plot(sma(zwap, 50), color=color.black)
plot(zwap, title="ZVWAP", color=zwap > 0 ? color.green : color.red, style=plot.style_columns, linewidth=2)
bgcolor(bg_color)

Overview

SPX Sentiment colours the background by whether the ratio is above or below its 200-bar average. Inputs set the length, smoothness, mean length and several band levels. It requests data from other symbols, so it relies on them being available.

Details

Published by

nvFede on GitHub

Code credit

QuantStreet, as written in the script's header

Type

Indicator, Pine Script v4

Draws

Separate pane below the chart

Markets

Indices

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
lengthint50length
Smoothneesint3smoothness
Mean Lengthint100mean_line
upperTopint5upperTop
upperBottomfloat5.0upperBottom
lowerTopint-5lowerTop
lowerBottomfloat-5.0lowerBottom
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

261 stars

This indicator calculates standardized z-scores of price data across four different lookback periods (6, 14, 26, and 100). Standardizing data subtracts the moving average from the price and divides by the standard deviation. It applies a Double Exponential Mov

Indicator v5 Mean reversionVolatility & bands
114 stars

This indicator implements a dual-direction variation of the Williams Vix Fix oscillator in a separate pane. It normalizes price data using min-max scaling to compute both upward and downward synthetic volatility metrics across two selectable calculation modes

Indicator v4 Volatility & bandsMean reversion
Updated 1 year ago · None stated GitHub repository of Combo Williams Vix Fix (Twin)
99 stars

The Mean Squared Error indicator calculates the mean of squared differences between a source series and its EMA, averaged via a rolling buffer acting as SMA. This error metric plots as a filled red area on a separate pane, while the EMA overlays as a yellow li

Indicator v6 Volatility & bandsMean reversion
Updated 4 weeks ago · Apache-2.0 GitHub repository of Mean Squared Error (MSE)

This indicator classifies market behavior into momentum, mean-reversion, noise, or mixed regimes. It fuses four statistical predictability sensors—Variance Ratio across multiple horizons, return autocorrelation, Hurst exponent approximation, and fractal effici

Indicator v6 TrendMean reversion
Updated 2 days ago · MIT GitHub repository of Predictability Regime Index [WavesUnchained]

Variance Ratio Test

by Anderson-ALGO
9 stars

This indicator calculates the Variance Ratio Test statistic to evaluate random walk behavior across multiple sampling periods. It computes log returns, base period variance over a specified lookback window, and scaled multi-period variances to determine test Z

Indicator v4 Volatility & bandsMean reversion
Updated 5 years ago · None stated GitHub repository of Variance Ratio Test

This indicator builds a channel from a Hull moving average of the source and an ATR scaled by a band multiplier, then normalizes price inside that channel into a 0 to 100 oscillator. It smooths the result with a weighted moving average and plots the line in a

Indicator v6 Mean reversionVolatility & bands
Updated 3 months ago · None stated GitHub repository of Radiant Mean Reversion Channels [Pineify]

More Volatility & bands scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers