K's Volatility Bands
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Sofien-Kaabar

//@version=5
indicator("K's Volatility Bands", overlay = true)
lookback = input(defval = 13, title = 'Lookback')
multiplier = input(defval = 2, title = 'Multiplier')

median = (ta.highest(high, lookback) + ta.lowest(low, lookback)) / 2

maximum_volatility = ta.highest(ta.stdev(close, lookback), lookback)

upper_band = median + (multiplier * maximum_volatility)
lower_band = median - (multiplier * maximum_volatility)

plot(upper_band, color = color.red)
plot(median, color = close > median ? color.blue: color.black, linewidth = 2)
plot(lower_band, color = color.green)