Volume Delta Candles
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © LeafAlgo

//@version=5
indicator("Volume Delta Candles", overlay=false)

// Calculate volume delta (buying volume - selling volume)
buyVolume = na(volume) ? na : (close > open) ? volume : 0
sellVolume = na(volume) ? na : (close < open) ? volume : 0
volumeDelta = buyVolume - sellVolume

// Custom OHLC values based on volume delta
customOpen = close - volumeDelta
customClose = close + volumeDelta
customHigh = close > customOpen ? close : customOpen
customLow = close > customOpen ? customOpen : close

// Plot the custom candles
plotcandle(open=customOpen, high=customHigh, low=customLow, close=customClose, title="Volume Delta Candles", color=volumeDelta >= 0 ? color.lime : color.fuchsia, wickcolor=color.gray, bordercolor=color.white, editable=false)
barcolor(volumeDelta >= 0 ? color.lime : color.fuchsia)
hline(0)