TFS Volume Oscillator Noise Filtered
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © MightyZinger
//@version=4

study(title="TFS Volume Oscillator Noise Filtered", shorttitle="MZ TFS")

uha   =input(true, title="Use Heikin Ashi Candles")
chartResolution = input("",type=input.resolution, title="Chart Resolution")

// Use only Heikinashi Candles for all calculations
haclose = uha ? security(heikinashi(syminfo.tickerid), chartResolution, close) : security(syminfo.tickerid, chartResolution, close)
haopen = uha ? security(heikinashi(syminfo.tickerid), chartResolution, open) : security(syminfo.tickerid, chartResolution, open)
hahigh = uha ? security(heikinashi(syminfo.tickerid), chartResolution, high) : security(syminfo.tickerid, chartResolution, high)
halow = uha ?security(heikinashi(syminfo.tickerid), chartResolution, low) : security(syminfo.tickerid, chartResolution, low)

vol = security(syminfo.tickerid, chartResolution, volume)

volLen = input(30, minval=1,title="Volume Length", group="Indicator Parameters")
volMAlen = input(14, minval=1,title="Volume MA Length", group="Indicator Parameters")
volMAtype = input(title="Volume MA Type", type=input.string, group="Indicator Parameters", defval="HMA", options=["LRC","HMA"])

nVolAccum = sum(iff(haclose > haopen, vol, iff(haclose < haopen, -vol, 0))  ,volLen)
nRes = nVolAccum / volLen
volMA = iff(volMAtype=="HMA", hma(nRes , volMAlen), linreg(nRes , volMAlen,0))


//Oscillator Plot

hline(0, color=color.red, linestyle=hline.style_dotted)

col_grow_above = input(#08FF08, "Above   Grow", group="Histogram", inline="Above")
col_fall_above = input(#B2DFDB, "Fall", group="Histogram", inline="Above")
col_grow_below = input(#FFCDD2, "Below Grow", group="Histogram", inline="Below")
col_fall_below = input(#E10600, "Fall", group="Histogram", inline="Below")
hist_col = (nRes>=0 ? (nRes[1] < nRes ? col_grow_above : col_fall_above) : (nRes[1] < nRes ? col_grow_below : col_fall_below))
plot(nRes, title="Histogram", style=plot.style_columns, color=hist_col)


// MA Coloring
bullColor = color.from_gradient(volMA, 50, 80, color.new(#f1fd6d, 70), color.new(#f1fd6d, 0))
bearColor = color.from_gradient(volMA, 20, 50, color.new(#485cff,   0), color.new(#485cff, 70))
volMAcol = volMA > 0 ? bullColor : bearColor
plot(volMA, "Signal", color = volMAcol, linewidth=2)

// ---Bar Color---
show_color_bar = input(title='Color Bars', defval=true)
barcolor(show_color_bar ? hist_col : na)
