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

//@version=5
indicator("range_stat")

long    = input(5, "long range length")
short   = input(1, "short range length") 
ma_len  = input(5, "ma length")

l_rng   = ta.highest(high, long) - ta.lowest(low, long)
s_rng   = ta.highest(high, short) - ta.lowest(low, short)
pct     = s_rng / l_rng
avg     = ta.sma(pct, ma_len)

var float[] avgs = array.new<float>()

array.push(avgs, avg)

mu      = array.avg(avgs)
stdev   = array.stdev(avgs) 

plot(avg)
plot(mu, color = color.red)
plot(mu + 2 * stdev, color = color.fuchsia)
plot(mu - 2 * stdev, color = color.fuchsia)

