Money Flow Index/MFIma/smooth vol-mfi
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © adishaz

//@version=5
indicator(title="Money Flow Index/MFIma/smooth vol-mfi", shorttitle="MFI", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
length = input.int(title="Length mfi", defval=14, minval=1, maxval=2000)
lengthMA = input.int(title="Length mfi-MA", defval=5, minval=1, maxval=2000)
lengthMAvol = input.int(title="Length MA VOL for smooth mfi", defval=5, minval=1, maxval=2000)

src = input(hlc3)
mf = ta.mfi(src, length)
MF= ta.sma(mf,lengthMA )
plot(mf, "MF", color=#7E57C2)
plot(MF, "MFma", color=#040108)
overbought=hline(80, title="Overbought", color=#787B86)
hline(50, "Middle Band", color=color.new(#787B86, 50))
oversold=hline(20, title="Oversold", color=#787B86)
fill(overbought, oversold, color=color.rgb(126, 87, 194, 90), title="Background")


volMA= ta.ema(volume,lengthMAvol)
float upper = math.sum(volMA * (ta.change(src) <= 0.0 ? 0.0 : src), length)
float lower = math.sum(volMA * (ta.change(src) >= 0.0 ? 0.0 : src), length)
mfi = 100.0 - (100.0 / (1.0 + upper / lower))

plot(mfi, "MFI SMOOTH", color=color.rgb(240, 6, 25))


