Indicator · Pine Script v4 · Own pane

Volatility Oscillator

by jubayernil· code credited to veryfid

This indicator measures intrabar volatility by plotting price spikes (close minus open) alongside standard deviation upper and lower bands in a separate pane.

View on GitHub

Repaints

GitHub stars1on the repository
Pine versionv4older, still runs
Lines of code147
Settings6inputs
LicenceNone statedfile: MPL-2.0
Last update3 years ago13 Apr 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

147 lines of Pine Script v4 from indicator/volatility-oscillator-indicator.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

volatility-oscillator-indicator.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © veryfid

//@version=4
study("Volatility Oscillator", resolution = "")
length = input(100)
spike = close - open
x = stdev(spike,length)
y = stdev(spike,length) * -1

plot(spike, color = color.white, linewidth = 2, title = "Spike Linel")

p1 = plot(x, "Upper Line")
p2 = plot(y, "Lower Line")

plot(0, color= color.gray, title= "Zero Line")

plot(spike, color= color.blue, style=plot.style_area, transp=80, title = "Spike Fill")

osc2 = spike

lbR = 5
lbL = 5
rangeUpper =60
rangeLower = 5
plotBull = input(title="Plot Bullish", defval=true)
plotHiddenBull = input(title="Plot Hidden Bullish", defval=false)
plotBear = input(title="Plot Bearish", defval=true)
plotHiddenBear = input(title="Plot Hidden Bearish", defval=false)
delay_plot_til_closed = input(title="Delay diversion plot until candle is closed (don't repaint)", defval=false)
bearColor = color.red
bullColor = color.green
hiddenBullColor = color.new(color.green, 80)
hiddenBearColor = color.new(color.red, 80)
textColor = color.white
noneColor = color.new(color.white, 100)

repaint = (not(delay_plot_til_closed) or barstate.ishistory or barstate.isconfirmed)

plFound = na(pivotlow(osc2, lbL, lbR)) ? false : true
phFound = na(pivothigh(osc2, lbL, lbR)) ? false : true
_inRange(cond) =>
    bars = barssince(cond == true)
    rangeLower <= bars and bars <= rangeUpper

//------------------------------------------------------------------------------
// Regular Bullish
// Osc: Higher Low

oscHL = osc2[lbR] > valuewhen(plFound, osc2[lbR], 1) and _inRange(plFound[1])

// Price: Lower Low

priceLL = low[lbR] < valuewhen(plFound, low[lbR], 1)
bullCond = plotBull and priceLL and oscHL and plFound and repaint


plotshape(
     bullCond ? osc2[lbR] : na,
     offset=-lbR,
     title="Regular Bullish Label",
     text="R",
     style=shape.labelup,
     location=location.absolute,
     color=bullColor,
     textcolor=textColor,
     transp=0
     )

//------------------------------------------------------------------------------
// Hidden Bullish
// Osc: Lower Low

oscLL = osc2[lbR] < valuewhen(plFound, osc2[lbR], 1) and _inRange(plFound[1])

// Price: Higher Low

priceHL = low[lbR] > valuewhen(plFound, low[lbR], 1)
hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound and repaint



plotshape(
     hiddenBullCond ? osc2[lbR] : na,
     offset=-lbR,
     title="Hidden Bullish Label",
     text="H",
     style=shape.labelup,
     location=location.absolute,
     color=bullColor,
     textcolor=textColor,
     transp=0
     )

//------------------------------------------------------------------------------
// Regular Bearish
// Osc: Lower High

oscLH = osc2[lbR] < valuewhen(phFound, osc2[lbR], 1) and _inRange(phFound[1])

// Price: Higher High

priceHH = high[lbR] > valuewhen(phFound, high[lbR], 1)

bearCond = plotBear and priceHH and oscLH and phFound and repaint



plotshape(
     bearCond ? osc2[lbR] : na,
     offset=-lbR,
     title="Regular Bearish Label",
     text="R",
     style=shape.labeldown,
     location=location.absolute,
     color=bearColor,
     textcolor=textColor,
     transp=0
     )

//------------------------------------------------------------------------------
// Hidden Bearish
// Osc: Higher High

oscHH = osc2[lbR] > valuewhen(phFound, osc2[lbR], 1) and _inRange(phFound[1])

// Price: Lower High

priceLH = high[lbR] < valuewhen(phFound, high[lbR], 1)

hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound and repaint



plotshape(
     hiddenBearCond ? osc2[lbR] : na,
     offset=-lbR,
     title="Hidden Bearish Label",
     text="H",
     style=shape.labeldown,
     location=location.absolute,
     color=bearColor,
     textcolor=textColor,
     transp=0
     )

//barcolor(color = spike > 0 ? color.green : color.red )

Overview

Volatility Oscillator identifies regular and hidden bullish or bearish divergences by comparing pivot points of the oscillator against price action. Users can toggle specific divergence labels and enable a setting to delay divergence plots until candle closure to reduce repainting.

Details

Published by

jubayernil on GitHub

Code credit

veryfid, as written in the script's header

Type

Indicator, Pine Script v4

Draws

Separate pane below the chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)

Settings

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

SettingTypeDefaultVariable
lengthint100length
Plot BullishbooltrueplotBull
Plot Hidden BullishboolfalseplotHiddenBull
Plot BearishbooltrueplotBear
Plot Hidden BearishboolfalseplotHiddenBear
Delay diversion plot until candle is closed (don't repaint)boolfalsedelay_plot_til_closed
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

330 stars

This indicator plots a TTM Squeeze momentum oscillator and a MACD line in a separate pane. It builds the squeeze oscillator from a linear regression of price against a high-low and simple moving average midpoint, and colors the area by slope and sign. Circles

Indicator v5 Oscillators & momentumVolatility & bands
Updated 2 months ago · None stated GitHub repository of TTM Squeeze + MACD line [Alorse]

Bubbles Indicator

by capissimo
114 stars

The Bubbles Indicator measures volatility squeezes and expansion bursts using Bollinger Bands combined with a sinusoid oscillator and RSI divergence. It processes price data through scaled Bollinger Bands to highlight volatility changes while confirming trend

Indicator v4 Volatility & bandsOscillators & momentum Repaints
Updated 1 year ago · None stated GitHub repository of Bubbles Indicator

TTM Squeeze Divergence

by TamaraKGreen
46 stars

The TTM Squeeze Divergence indicator plots a classic TTM Squeeze momentum oscillator in a separate pane alongside Bollinger Bands and Keltner Channels squeeze status dots on the zero line. It detects regular and hidden bullish and bearish divergences between p

Indicator v6 Oscillators & momentumVolatility & bands Repaints
Updated 8 weeks ago · None stated GitHub repository of TTM Squeeze Divergence

Relative Strength Index

by deepentropy
13 stars

This indicator plots the Relative Strength Index in a separate pane from smoothed up and down price changes. It draws the RSI line with horizontal bands at 70, 50 and 30, plus overbought and oversold gradient fills. Optional settings add a smoothing moving ave

Indicator v6 Oscillators & momentumMoving averages
Updated 6 months ago · MIT GitHub repository of Relative Strength Index

QFA Pro Elite Refined

by JasonTeixeira
9 stars

This indicator plots a smoothed fear index in a separate pane. It measures how far the current low sits below the highest close over a lookback, scales that reading by an ATR percentile, and smooths it with a zero-lag EMA. A volatility regime raises or lowers

Indicator v6 Oscillators & momentumVolatility & bands
Updated 2 weeks ago · Custom licence GitHub repository of QFA Pro Elite Refined

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