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

//@version=5
indicator("FT Volatility Depth", overlay = false, precision=4)

length = input.int(7)
lower = ta.lowest(low, length)
higher = ta.highest(high, length)

depth = (higher-lower)/lower
extreme_vol = color.red
high_vol = color.orange
normal_vol = color.yellow
low_vol = color.green

bar_color = depth>=0.25 ? extreme_vol : depth>=0.125 and depth<0.25 ? high_vol : depth>=0.05 and depth<0.125 ? normal_vol : low_vol

plot(depth, linewidth = 2, color = bar_color, style = plot.style_histogram)

alertcondition(bar_color==extreme_vol, "Extreme Volatility")
alertcondition(bar_color==high_vol, "High Volatility")
alertcondition(bar_color==normal_vol, "Normal Volatility")
alertcondition(bar_color==low_vol, "Low Volatility")