Heiken Ashi Smoothed Net Volume
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mdenson
//@version=4
//Modified Volume net histogram by RafaelZioni

study("Heiken Ashi Smoothed Net Volume")

//==================================================================
//Heiken Ashi Candle Calculations
hkClose         = (open + high + low + close) / 4
hkOpen          = float(na)
hkOpen          := na(hkOpen[1]) ? (open + close) / 2 : (nz(hkOpen[1]) + nz(hkClose[1])) / 2
hkHigh          = max(high, max(hkOpen, hkClose))
hkLow           = min(low,  min(hkOpen, hkClose))
hkHl2           = (hkOpen + hkClose)/2
volumeHA        = security(heikinashi(syminfo.tickerid), timeframe.period, volume)

//===================================================================
//volume Net Histogram calculations
topwick         = iff(hkOpen<hkClose, hkHigh - hkClose, hkHigh - hkOpen)
bottomwick      = iff(hkOpen<hkClose, hkOpen-hkLow, hkClose-hkLow)
body            = iff(hkOpen<hkClose, hkClose-hkOpen, hkOpen-hkClose)
ohcl4           = (hkHigh+hkLow+hkOpen+hkClose)/4

fractionup      = iff( hkOpen<hkClose, (topwick + bottomwick + 2*body)/(2*topwick + 2*bottomwick + 2*body), (topwick + bottomwick)/(2*topwick + 2*bottomwick + 2*body) )
fractiondown    = iff( hkOpen<hkClose, (topwick + bottomwick)/(2*topwick + 2*bottomwick + 2*body), (topwick + bottomwick + 2*body)/(2*topwick + 2*bottomwick + 2*body) )
volumeup        = volume * fractionup * ohcl4

volumedown      = volume * fractiondown * ohcl4

netvolume       = volumeup - volumedown

lengthMA        =input(25, title="length")
netplot         = linreg(netvolume, lengthMA, -lengthMA)
lineColor       =  netplot > 0 ? color.green : color.red
v               = plot(netplot, title=" volume netflow", color=lineColor,style=plot.style_histogram, linewidth=3, transp=0)
plot(0)