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

//@version=5
indicator("Average_Vol")
i_date = input.time(timestamp("20 Oct 2021 6:00 +0300"), "Date", confirm = true)
From_Open_Mode = input.bool(false, "From_Open_Mode")

var Vol = 0.0
var Average_Vol = 0.0
var Max_Candle_Vol = 0.0
var Average_Of_Candle = 0.0

f_average(_src) =>
    // _src  : series to average.
    var _cumTotal = 0.0
    var _cumCount = 0.0
    _cumTotal := _cumTotal + _src
    _cumCount := _cumCount + 1
    Resultat = _cumTotal / _cumCount
    
Average_Of_Candle := (open + close) / 2
if (From_Open_Mode)
    Max_Candle_Vol := math.max((open - low), (high-open))
else
    Max_Candle_Vol := (high - low)
if time >= i_date
    Vol := Max_Candle_Vol / Average_Of_Candle * 100.0
    Average_Vol := f_average(Vol)

plot(Vol, "Vol")
plot(Average_Vol, "Avg_Vol", color.orange)
