Volume-Price Diff
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © siq_trader

//@version=5
indicator("Volume-Price Diff", overlay = true)

var bool initialized = false

varip int volumeChanges = 0
varip int priceChanges = 0
varip lastPrice = close
varip diffPercentage = 0

var color startLabelBgColor = #ffffff
var color startLabelTextColor = #8d8c8c

var color currentInfoLabelBgColor = #ece2e2
var color currentInfoLabelTextColor = #2c455a

if barstate.isnew
    volumeChanges := 0
    priceChanges := 0
    diffPercentage := 0
    lastPrice := close

if barstate.isrealtime
    if not initialized
        label.new(bar_index - 1, low, yloc = yloc.belowbar, color = startLabelBgColor, textcolor = startLabelTextColor, text = "start", style = label.style_arrowup)    
        initialized := true

    volumeChanges += 1
    if close != lastPrice
        priceChanges += 1

    diffPercentage := ((volumeChanges - priceChanges) / volumeChanges) * 100

    if barstate.isconfirmed
        label.new(bar_index, high, color = color.new(color.white, 90), tooltip = "Volume changes: " + str.tostring(volumeChanges) + "\n" + "Price changes: " + str.tostring(priceChanges) + "\n" + "Diff: " + str.tostring(diffPercentage, format.percent), size = size.tiny)
    else
        label.new(bar_index, high, yloc = yloc.abovebar, color = currentInfoLabelBgColor, textcolor = currentInfoLabelTextColor, text = "Volume changes: " + str.tostring(volumeChanges) + "\n" + "Price changes: " + str.tostring(priceChanges) + "\n" + "Diff: " + str.tostring(diffPercentage, format.percent))

plot(volumeChanges, color = color.new(color.white, 100), display = display.status_line)
plot(priceChanges, color = color.new(color.white, 100), display = display.status_line)
plot(diffPercentage, color = color.new(color.white, 100), display = display.status_line)