I used this signalgenerator code : def signalgenerator(df): open = df.Open.iloc[-1]…
- User
I used this 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 indicator ema = ta.trend.EMAIndicator(df['Close'], window=10)
# Calculate MA indicator ma = ta.trend.SMAIndicator(df['Close'], window=20) # Calculate EMA indicator ema_value = ema.ema_indicator()[-1] #get the EMA indicator value for the last value in the DataFrame ma_value = ma.sma_indicator()[-1] #get the MA 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_value and close<ma_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_value and close>ma_value): return 'buy' #No clear pattern with EMA and MA indicators else: return ''But time to time it gives me wrong signals , can you add in my code EMA 50, EMA 100 and EMA 200
- Assistant
Sure, here's the updated code with EMA 50, EMA 100, and EMA 200 added:
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 ma = ta.trend.SMAIndicator(df['Close'], window=20) # 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 ma_value = ma.sma_indicator()[-1] #get the MA 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 and close<ma_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 and close>ma_value): return 'buy' #No clear pattern with EMA and MA indicators else: return ''