# indie:lang_version = 5
from indie import indicator, plot, color, SeriesF, MutSeriesF, Optional

@indicator('Market Facilitation Index [TC]', overlay_main_pane=False)
@plot.columns(id='#plot_0')
def Main(self):
    # Calculate MFI for the current and previous bars
    MFI = MutSeriesF.new(1000000000 * (self.high[0] - self.low[0]) / self.volume[0])
    PreMFI = MutSeriesF.new(1000000000 * (self.high[1] - self.low[1]) / self.volume[1])
    
    # Calculate the bar states
    greenbar = (MFI[0] > PreMFI[0]) and (self.volume[0] > self.volume[1])
    fadebar = (MFI[0] < PreMFI[0]) and (self.volume[0] < self.volume[1])
    fakebar = (MFI[0] > PreMFI[0]) and (self.volume[0] < self.volume[1])
    squatbar = (MFI[0] < PreMFI[0]) and (self.volume[0] > self.volume[1])

    # Initialize bar_color with Optional[color] type
    bar_color = color.MAROON if squatbar else color.GREEN

    # Return the value of MFI for the current bar
    return plot.Columns(MFI[0], color = bar_color)
