Indicator · Pine Script v5 · Own pane

[TVT] VIX Short Term Danger

by namuan

Calculates and plots moving averages on selected VIX volatility terms (VIX9D, VIX, VIX3M, or VIX6M) in a separate pane.

View on GitHub

GitHub stars318on the repository
Pine versionv5runs as is
Lines of code70
Settings4inputs
LicenceMIT
Last update2 months ago18 Aug 2026

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

70 lines of Pine Script v5 from tv-scripts/tvt-vix-danger.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

tvt-vix-danger.pine
//@version=5
indicator(title="[TVT] VIX Short Term Danger", shorttitle="[TVT] VIX-RISK", overlay=false)

// Input parameters
short_ma_length = input.int(3, title="Short MA Length", minval=1)
long_ma_length = input.int(8, title="Long MA Length", minval=1)
ma_type = input.string("EMA", title="MA Type", options=["EMA", "SMA"])

// Single selection for VIX timeframe
vix_option = input.string("VIX9D", title="Select VIX", options=["VIX9D", "VIX", "VIX3M", "VIX6M"])

// Fetch VIX data using chart's timeframe
vix9d = request.security("VIX9D", timeframe.period, close)
vix1m = request.security("VIX", timeframe.period, close)
vix3m = request.security("VIX3M", timeframe.period, close)
vix6m = request.security("VIX6M", timeframe.period, close)

// Function to calculate MA based on type
calcMA(source, length) =>
    ma_type == "EMA" ? ta.ema(source, length) : ta.sma(source, length)

// Calculate MAs
short_ma_9d = calcMA(vix9d, short_ma_length)
long_ma_9d = calcMA(vix9d, long_ma_length)

short_ma_1m = calcMA(vix1m, short_ma_length)
long_ma_1m = calcMA(vix1m, long_ma_length)

short_ma_3m = calcMA(vix3m, short_ma_length)
long_ma_3m = calcMA(vix3m, long_ma_length)

short_ma_6m = calcMA(vix6m, short_ma_length)
long_ma_6m = calcMA(vix6m, long_ma_length)

// Define colors with transparency
purple_transp = color.new(color.red, 40)
orange_transp = color.new(color.orange, 50)

// Adjust background colors based on short_ma_9d vs short_ma_3m comparison
green_transp = short_ma_9d < short_ma_3m ? color.new(color.green, 80) : color.new(color.green, 90)
red_transp = short_ma_9d > short_ma_3m ? color.new(color.red, 80) : color.new(color.red, 90)

// Get current short and long MA values based on selection
current_short_ma = switch vix_option
    "VIX9D" => short_ma_9d
    "VIX" => short_ma_1m
    "VIX3M" => short_ma_3m
    "VIX6M" => short_ma_6m

current_long_ma = switch vix_option
    "VIX9D" => long_ma_9d
    "VIX" => long_ma_1m
    "VIX3M" => long_ma_3m
    "VIX6M" => long_ma_6m

// Set background color based on MA crossover
bgcolor(current_short_ma > current_long_ma ? red_transp : green_transp)

// Plot based on selection
plot(vix_option == "VIX9D" ? short_ma_9d : na, color=purple_transp, style=plot.style_line, linewidth=2)
plot(vix_option == "VIX9D" ? long_ma_9d : na, color=orange_transp, style=plot.style_line, linewidth=1)

plot(vix_option == "VIX" ? short_ma_1m : na, color=purple_transp, style=plot.style_line, linewidth=2)
plot(vix_option == "VIX" ? long_ma_1m : na, color=orange_transp, style=plot.style_line, linewidth=1)

plot(vix_option == "VIX3M" ? short_ma_3m : na, color=purple_transp, style=plot.style_line, linewidth=2)
plot(vix_option == "VIX3M" ? long_ma_3m : na, color=orange_transp, style=plot.style_line, linewidth=1)

plot(vix_option == "VIX6M" ? short_ma_6m : na, color=purple_transp, style=plot.style_line, linewidth=2)
plot(vix_option == "VIX6M" ? long_ma_6m : na, color=orange_transp, style=plot.style_line, linewidth=1)

Overview

The script computes user-defined short and long moving averages using EMA or SMA. It shades the background red when the short-term moving average crosses above the long-term moving average, indicating elevated volatility risk, and green when below. The background shading intensity also reflects the term structure relationship between 9-day and 3-month volatility.

Details

Published by

namuan on GitHub

Type

Indicator, Pine Script v5

Draws

Separate pane below the chart

Category

Volatility & bands, Moving averages

Markets

Indices, Stocks

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.

Topics

trading-strategiesmarket-analysisdtalestock-market-analysistelegram-botearnings-calendaroptions-trading

Settings

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

SettingTypeDefaultVariable
Short MA Lengthint3short_ma_length
Long MA Lengthint8long_ma_length
MA TypestringEMAma_type
Select VIXstringVIX9Dvix_option
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

MACD-V

by harryguiacorn
219 stars

MACD-V is a volatility-normalized momentum indicator based on research by Alex Spiroglou. It calculates the standard MACD histogram and normalizes it by dividing by the Average True Range (ATR). Plotted in a separate pane as a colored histogram, it includes us

Indicator v5 Oscillators & momentumVolatility & bands
Updated 1 year ago · None stated GitHub repository of MACD-V

MultiIndicator

by capissimo
114 stars

MultiIndicator combines multiple technical indicators into a single separate pane to save chart space. It calculates and displays market regime detection based on ordinary least squares regression, a Holt exponential smoothing crossover, normalized RSI, ADX, a

Indicator v4 Oscillators & momentumTrend
Updated 1 year ago · None stated GitHub repository of MultiIndicator

The AMFM indicator decomposes price movements into amplitude and frequency components using Ehlers' digital signal processing methods. It whitens the derivative as close minus open, then computes AM as the smoothed envelope of the absolute difference over 4 pe

Indicator v6 Volatility & bandsMoving averages
Updated 4 weeks ago · Apache-2.0 GitHub repository of AMFM - Ehlers AM Detector / FM Demodulator

PPO ATR Bands

by cryptorife
75 stars

PPO ATR Bands plots a percentage price oscillator in a separate pane. It compares a Hull average of typical price with a volume-weighted exponential average of Parabolic SAR, then scales three true-range bands around the slow average into matching oscillator l

Indicator v4 Oscillators & momentumMoving averages
Updated 3 years ago · GPL-3.0 GitHub repository of PPO ATR Bands

This indicator plots a relative strength index in a separate pane. It calculates RSI from the average of the previous ten opens rather than the current bar, so that source does not change during the live candle. A moving average of the RSI is plotted and can b

Indicator v5 Oscillators & momentumMoving averages
Updated 2 years ago · None stated GitHub repository of No Repaint - Relative Strength Index

More indicators

Trade Your Charts With a Regulated Broker

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

Compare brokers