I used this signalgenerator code: def signalgenerator(df): open = df.Open.iloc[-1] close…
- 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 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 ''How I can add Bolinger Bands indicator in my code ?
- Assistant
You can add Bolinger Bands indicator to your code by calculating the upper and lower bands using the ta.volatility.BollingerBands indicator. Here's an updated version of your code that includes Bolinger Bands:
import ta.volatility
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]