Volatility Speedometer
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © LeafAlgo

//@version=5
indicator("Volatility Speedometer", overlay=false)

lookbackPeriod = input(14, "Lookback Period")
volatilityMeasure = ta.atr(14) // Example: Using Average True Range (ATR) as the volatility measure

// Calculate the rate of change of volatility
volatilityChange = (volatilityMeasure - volatilityMeasure[lookbackPeriod]) / volatilityMeasure[lookbackPeriod] * 100

// Calculate the SMA of the Volatility Change
vcsma = ta.sma(volatilityChange, lookbackPeriod)

// Plotting the Volatility Speedometer histogram and the SMA
plot(volatilityChange, "Volatility Speed", color=color.blue, style=plot.style_histogram, linewidth = 4)
plot(vcsma, 'Volatility Speed Average Line', color=color.maroon, linewidth=4)

// Customizing the color zones based on volatility speed levels
threshold1 = input(1.5, "Threshold 1")
threshold2 = input(3, "Threshold 2")

// Additional color stuff
bgcolor(volatilityChange >= threshold2 ? color.lime : volatilityChange >= threshold1 ? color.yellow : color.fuchsia, transp=80)
barcolor(volatilityChange >= threshold2 ? color.lime : volatilityChange >= threshold1 ? color.yellow : color.fuchsia)
