Indicator · Pine Script v5 · Own pane

Volatility Oscillator with Quick Estimate and Forecast

by jawauntb

This indicator estimates realized volatility in a separate pane.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code47
Settings5inputs
LicenceGPL-3.0
Last update2 years ago22 May 2024

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

47 lines of Pine Script v5 from volatility-estimation.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

volatility-estimation.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0.
// © jawauntb

//@version=5
indicator("Volatility Oscillator with Quick Estimate and Forecast", overlay=false)

// Input parameters
shortTermLength = input.int(13, minval=1, title="Short Term Length")
mediumTermLength = input.int(20, minval=1, title="Medium Term Length")
longTermLength = input.int(100, minval=1, title="Long Term Length")
forecastLength = input.int(13, minval=1, title="Forecast Length") // Set forecast length to 13 days
annualizationFactor = input.int(252, title="Annualization Factor") // Use 252 for trading days in a year

// Fetch the most recent daily close prices
dailyClose = request.security(syminfo.tickerid, "D", close)

// Use the previous day's close in the morning until the current day's close is available
intradayClose = close
previousDailyClose = request.security(syminfo.tickerid, "D", close[1])

// Calculate returns using the most recent completed daily close prices and intraday close prices
dailyReturn = math.log(dailyClose / previousDailyClose)
intradayReturn = math.log(intradayClose / previousDailyClose)

// Calculate annualized volatilities
shortTermVol = ta.stdev(intradayReturn, shortTermLength) * math.sqrt(annualizationFactor) * 100
mediumTermVol = ta.stdev(intradayReturn, mediumTermLength) * math.sqrt(annualizationFactor) * 100
longTermVol = ta.stdev(intradayReturn, longTermLength) * math.sqrt(annualizationFactor) * 100

// Calculate quick and dirty estimate (daily return * 20)
quickEstimateVol = ta.stdev(intradayReturn, shortTermLength) * 20 * 100

// Calculate forecast volatility (proxy for next 13 days based on last 13 days)
forecastVol = ta.stdev(intradayReturn, forecastLength) * math.sqrt(annualizationFactor) * 100

// Plot the volatilities
plot(shortTermVol, color=color.blue, title="Short-Term Volatility")
plot(mediumTermVol, color=color.orange, title="Medium-Term Volatility")
plot(longTermVol, color=color.red, title="Long-Term Volatility")
plot(quickEstimateVol, color=color.purple, title="Quick Estimate Volatility")
plot(forecastVol, color=color.teal, title="Forecast Volatility (Next 13 days)")

// Optional: Plot as an oscillator
hline(0, "Zero Line", color=color.gray)
plot(shortTermVol - mediumTermVol, color=color.green, title="Short vs Medium Term Spread")
plot(shortTermVol - longTermVol, color=color.purple, title="Short vs Long Term Spread")
plot(mediumTermVol - longTermVol, color=color.yellow, title="Medium vs Long Term Spread")

Overview

Volatility Oscillator with Quick Estimate and Forecast computes log returns from the current price and the previous daily close, then annualizes the standard deviation over short, medium, and long lookbacks. It also plots a quicker estimate that multiplies short-term deviation by twenty and a forecast that annualizes the standard deviation of the most recent forecast window. Users can change those lengths and the annualization factor. Difference lines compare the three volatility terms against a zero line. It does not generate entries or exits.

Details

Published by

jawauntb on GitHub

Type

Indicator, Pine Script v5

Draws

Separate pane below the chart

Category

Volatility & bands

Markets

Any symbol

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
Short Term Lengthint13shortTermLength
Medium Term Lengthint20mediumTermLength
Long Term Lengthint100longTermLength
Forecast Lengthint13forecastLength
Annualization Factorint252annualizationFactor
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

This indicator calculates the distribution of close-to-close percentage changes using rate of change on closing prices. It bins percentage changes into intervals of 0.25 percent increments from negative to positive values and plots a normalized cumulative hist

Indicator v4 Volatility & bands
Updated 10 days ago · GPL-3.0 GitHub repository of Close-to-Close % Change Distribution

This indicator plots a Supertrend-based trend-following setup in a separate pane and skips conditions it treats as a sideways market. A volatility range is built from an ATR value, with RMA, SMA, EMA, or WMA smoothing, or from a fixed point distance. Optional

Indicator v5 TrendVolatility & bands
Updated 1 year ago · MPL-2.0 GitHub repository of Trend Following Setup - Sideways Market Skipper
330 stars

This indicator plots candle range and open-to-close movement as percentages in a separate pane. Range is the high-low difference divided by the low, and change is the close-open difference divided by the open. Both series draw as columns. Teal columns show ran

Indicator v5 Volatility & bands
Updated 2 months ago · None stated GitHub repository of Percent & Volatility [Alorse]

Mojito v3 Strategy

by namuan
318 stars

The Mojito v3 Strategy indicator evaluates volatility term structure by calculating the ratio between front-month and second-month VIX futures contracts. It smooths this ratio using a configurable median filter and compares the result against user-defined uppe

Indicator v5 Volatility & bands
Updated 2 months ago · MIT GitHub repository of Mojito v3 Strategy

Function - Logistic Equation

by ricardosantos79
261 stars

Calculates dynamic modeling values by applying a mathematical logistic differential equation to price change over a specified lookback length. It measures price momentum relative to the recent high-low price range. The script plots positive and negative logist

Indicator v5 Oscillators & momentumVolatility & bands
Updated 4 years ago · None stated GitHub repository of Function - Logistic Equation

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

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