I used thi signal generator code: def signal_generator(df):
    open = df.Open.iloc[-1]
    close = df.Close.iloc[-1]
    previous_open = df.Open.iloc[-2]
    previous_close = df.Close.iloc[-2]
    # Calculate EMA indicators
    ema_10 = ta.trend.EMAIndicator(df['Close'], window=10)
    ema_50 = ta.trend.EMAIndicator(df['Close'], window=50)
    ema_100 = ta.trend.EMAIndicator(df['Close'], window=100)
    ema_200 = ta.trend.EMAIndicator(df['Close'], window=200)

    # Calculate MA indicator

    # Calculate EMA indicator values
    ema_10_value = ema_10.ema_indicator()[-1] #get the EMA 10 indicator value for the last value in the DataFrame
    ema_50_value = ema_50.ema_indicator()[-1] #get the EMA 50 indicator value for the last value in the DataFrame
    ema_100_value = ema_100.ema_indicator()[-1] #get the EMA 100 indicator value for the last value in the DataFrame
    ema_200_value = ema_200.ema_indicator()[-1] #get the EMA 200 indicator value for the last value in the DataFrame

    #Bearish pattern with EMA and MA indicators
    if (open>close and
    previous_open<previous_close and
    close<previous_open and
    open>=previous_close and
    close<ema_10_value and close<ema_50_value and close<ema_100_value and close<ema_200_value):
        return 'sell'

    #Bullish pattern with EMA and MA indicators
    elif (open<close and
    previous_open>previous_close and
    close>previous_open and
    open<=previous_close and
    close>ema_10_value and close>ema_50_value and close>ema_100_value and close>ema_200_value):
        return 'buy'

    #No clear pattern with EMA and MA indicators
    else:
        return ''
But time to time it giveing me wrong signals  or on another hand it giveing me signal going in minus and when it needs to give me signal to close position and open new position it doesn't do them , if it possible give me irght code as solution