Detailed Volume (DV)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © KhashayarJan

//@version=5
indicator("DV", format = format.volume, overlay = false)

bColor = color.rgb(146,223,139)
sColor = color.rgb(254,150,149)
b2Color = color.rgb(146,223,139,50)
s2Color = color.rgb(254,150,149,50)

ShowDifference = input (defval = false, title = "Show Difference", tooltip = "If true, the filler column would just show the difference in volume, else it would show the whole volume traded for the stronger side")

BuyMA = input(defval = color.green, title = "Buy Moving Averate")
SellMA = input(defval = color.red, title = "Sell Moving Averate")
MAPeriod = input(defval = 14, title = "Moving Average Period")

vol = volume
shadow = (close > open) ? (high - close) + (open - low) : (high - open) + (close - low)

shadow := shadow * volume / (high - low)

    
buyVolume = (close > open) ? (close - open) * volume / (high - low) : 0
sellVolume = (open > close) ? (open - close) * volume / (high - low) : 0

plot(ta.sma(buyVolume + shadow / 2,MAPeriod), color = BuyMA)
plot(ta.sma(sellVolume + shadow / 2 ,MAPeriod), color = SellMA)

plot(volume, color = (close > open) ? b2Color : s2Color, style = plot.style_columns)
plot((close > open) ? ((close - open) * volume / (high - low)) + ((ShowDifference) ? 0 : shadow / 2) : ((open - close) * volume / (high - low)) + ((ShowDifference) ? 0 : shadow / 2), color = (close > open) ? bColor : sColor, style = plot.style_columns)
