Realtime Volume Analysis Toolbar
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © noop42

//@version=5
indicator("Realtime Volume Analysis Toolbar", shorttitle="RVAT", overlay=false, max_boxes_count=10000, max_lines_count=500, max_labels_count=500)

// Tooltips

// Options

varip cumulative_vol = 0.0
varip lastPrice = close
varip lastVolume = 0.0
varip upvol = 0.0
varip downvol = 0.0
varip ticknumber = 0
if barstate.isrealtime
    v = ticknumber == 0 ? volume : volume - lastVolume
    if close > lastPrice
        //cumulative_vol += v
        upvol += v
    else
        downvol += v

    delta = upvol - downvol
    delta_col = delta > 0 ? color.lime : color.red
    float askv_per = (upvol / (upvol + downvol)) *100
    askv_color = askv_per > 50.0 ? color.lime : color.red
    label.new(bar_index, 4.5, text=str.tostring(volume), style=label.style_none, textcolor=color.white)
    label.new(bar_index, 3.5, text="↑ "+str.tostring(upvol), style=label.style_none, textcolor=color.lime)
    label.new(bar_index, 2.5, text="↓ "+str.tostring(downvol), style=label.style_none, textcolor=color.red)
    label.new(bar_index, 1.5, text="⍙ "+str.tostring(delta), style=label.style_none, textcolor=delta_col)
    label.new(bar_index, 0.5, text="⇅ "+str.tostring(askv_per, "#.#")+"%", style=label.style_none, textcolor=askv_color)

    lastVolume := volume
    lastPrice := close
    ticknumber += 1
if barstate.isconfirmed
    lastVolume := 0.0
    lastPrice := close
    cumulative_vol := 0.0
    upvol := 0.0
    downvol := 0.0
    ticknumber := 0
hline(4.25, linestyle=hline.style_solid)
hline(3.25, linestyle=hline.style_dotted)
hline(2.25, linestyle=hline.style_dotted)
hline(1.25, linestyle=hline.style_dotted)
hline(0.25, linestyle=hline.style_dotted)
