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

//@version=5
indicator("Logarithmic Volatility")

high_t = math.log(high)- math.log(open)
low_t = math.log(low)- math.log(open)
close_t = math.log(close)- math.log(open)

vol_t = math.sqrt(0.5 * math.pow((high_t - low_t), 2) - (2 * math.log(2) - 1) * math.pow(close_t,2))

slow_length = input(21, title="Slow EMA Length")
fast_length = input(9, title="Fast EMA Length")
media_length = input(14, title="Media EMA Length")

slow = ta.ema(vol_t, slow_length)
fast = ta.ema(vol_t, fast_length)

// Añadimos la nueva media
media = ta.ema(vol_t, media_length)
color_media = fast < slow ? color.green : color.red

plot(media, color=color_media, linewidth=2)  // Grosor de la línea definido en 3
plot(media, color=color_media, style=plot.style_histogram, linewidth=2)

