// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © leocairos
//@version=5
indicator(title="Relative Strength Index And Money Flow Index", shorttitle="RSI x MFI", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
// RSI
rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI Settings")
rsiSourceInput = input.source(close, "Source", group="RSI Settings")
up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
rsiUpperBand = hline(70, "RSI Upper Band", color=color.new(#787B86, 50))
rsiLowerBand = hline(30, "RSI Lower Band", color=color.new(#787B86, 50))
plot(rsi, "RSI", color=#FB9A00)
//MFI
length = input.int(title="Length", defval=14, minval=1, maxval=2000)
src = hlc3
mf = ta.mfi(src, length)
plot(mf, "MF", color=#0045FE)
overbought=hline(80, title="Overbought", color=#787B86)
hline(50, "Middle Band", color=color.new(#787B86, 50))
oversold=hline(20, title="Oversold", color=#787B86)