Intraday Hourly Volume
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RicardoSantos

//@version=4
study(title='Intraday Hourly Volume')
var float[] volumes = array.new_float(24, 0.0)
var int[] counters = array.new_int(24, 0)

var line[] lines = array.new_line(24)
var label[] labels = array.new_label(24)
if barstate.isfirst
    for _i = 0 to 23
        array.set(lines, _i, line.new(bar_index, 0.0, bar_index, 0.1, style=line.style_arrow_right, width=2))
        array.set(labels, _i, label.new(bar_index, 0.0, str.format('{0}', _i), style=label.style_label_up))

int h = hour(time)
// label.set_tooltip(array.get(labels, 0), str.tostring(h))
if change(h) != 0
    _volume = array.get(volumes, h) + volume
    _count = array.get(counters, h) + 1
    array.set(volumes, h, _volume)
    array.set(counters, h, _count)
    line _line = array.get(lines, h)
    line.set_y1(_line, _volume / _count)
    line.set_y2(_line, volume)
    label.set_color(array.get(labels, h), color=color.red)
    label.set_color(array.get(labels, (24 + h - 1) % 24), color=color.blue)

if barstate.islastconfirmedhistory
    for _i = 0 to 23
        line _line = array.get(lines, _i)
        label _label = array.get(labels, _i)
        int _idx = bar_index + 10 * _i
        line.set_x1(_line, _idx)
        line.set_x2(_line, _idx)
        label.set_x(_label, _idx)
