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

//@version=5
indicator("Adjusted OBV")

totalwidth = nz((high - low),0)

topwickwidth = if close >= open
    high - close
else
    high - open

bottomwickwidth = if close >= open
    open - low
else
    close - low

candlewidth = if close >= open
    close - open
else
    open - close

topwickpercent = topwickwidth / totalwidth
bottomwickpercent = bottomwickwidth / totalwidth
candlepercent = candlewidth / totalwidth
wickvolume = volume * (topwickpercent + bottomwickpercent)
candlevolume = volume * candlepercent
volatility = (topwickwidth + bottomwickwidth) / totalwidth

if close >= open
    candlevolume := 0 + candlevolume
else
    candlevolume := 0 - candlevolume

var float aobv = nz(candlevolume, 0)
aobv := aobv + nz(candlevolume,0)

plot(aobv, color=color.rgb(255, 136, 0))
plot(ta.obv, color=color.rgb(0, 13, 255))

