# indie:lang_version = 5
from indie import indicator, plot, color, param, MutSeriesF
from indie.algorithms import Ema

@indicator("Elder's Force Index (FI)", overlay_main_pane=False)
@param.int('length', default=13, min=1, title='EMA Length')
@plot.line(id='#plot_0')
def Main(self, length):
    # Create a mutable time series for the Force Index
    fi_series = MutSeriesF.new((self.close[0] - self.close[1]) * self.volume[0])
    
    # Apply exponential smoothing
    smoothed_fi = Ema.new(fi_series, length)[0]

    # Determine the color of the indicator line
    fi_color = color.GREEN if smoothed_fi > 0 else color.RED

    return plot.Line(smoothed_fi, color=fi_color)
