//@version=2
define(title="MFI Indicator", position="offchart", axis=true);
timeseries ohlcvData = ohlcv(symbol=currentSymbol, exchange=currentExchange);
var mfiValue = mfi(source=ohlcvData, period=14);
// Color based on overbought/oversold
var colorIndex = mfiValue > 80 ? 0 : (mfiValue < 20 ? 1 : 2);
plotLine(value=mfiValue, width=2, colors=["red", "green", "blue"], colorIndex=colorIndex, label=["MFI"], desc=["Money Flow Index"]);
hline(value=80, color="red", width=1, style="dashed", label="Overbought");
hline(value=20, color="green", width=1, style="dashed", label="Oversold");