I have this code: def signalgenerator(df): if df is None: return '' emaanalysis = []…
- User
I have this code: def signal_generator(df): if df is None: return '' ema_analysis = [] candle_analysis = []
df['EMA20'] = df['Close'].ewm(span=20, adjust=False).mean() df['EMA50'] = df['Close'].ewm(span=50, adjust=False).mean() df['EMA14'] = df['Close'].ewm(span=14, adjust=False).mean() if ( df['EMA14'].iloc[-1] > df['EMA50'].iloc[-1] and df['EMA14'].iloc[-2] < df['EMA50'].iloc[-2] ): ema_analysis.append('golden_cross') elif ( df['EMA14'].iloc[-1] < df['EMA50'].iloc[-1] and df['EMA14'].iloc[-2] > df['EMA50'].iloc[-2] ): ema_analysis.append('death_cross') if ( df['Close'].iloc[-1] > df['Open'].iloc[-1] and df['Open'].iloc[-1] > df['Low'].iloc[-1] and df['High'].iloc[-1] > df['Close'].iloc[-1] ): candle_analysis.append('bullish_engulfing') elif ( df['Close'].iloc[-1] < df['Open'].iloc[-1] and df['Open'].iloc[-1] < df['High'].iloc[-1] and df['Low'].iloc[-1] > df['Close'].iloc[-1] ): candle_analysis.append('bearish_engulfing') bollinger_std = df['Close'].rolling(window=20).std() df['UpperBand'] = df['EMA20'] + (bollinger_std * 2) df['LowerBand'] = df['EMA20'] - (bollinger_std * 2) if ( df['Close'].iloc[-1] > df['UpperBand'].iloc[-1] and df['Close'].iloc[-2] < df['UpperBand'].iloc[-2] ): candle_analysis.append('upper_band_breakout') elif ( df['Close'].iloc[-1] < df['LowerBand'].iloc[-1] and df['Close'].iloc[-2] > df['LowerBand'].iloc[-2] ): candle_analysis.append('lower_band_breakout') if ('golden_cross' in ema_analysis and 'bullish_engulfing' in candle_analysis) or 'lower_band_breakout' in candle_analysis: return 'buy' elif ('death_cross' in ema_analysis and 'bearish_engulfing' in candle_analysis) or 'upper_band_breakout' in candle_analysis: return 'sell' else: return ''Can you remove bolinger bands please
- Assistant
Certainly! Below is the modified code without the Bollinger Bands calculations:
def signal_generator(df): if df is None: return '' ema_analysis = [] candle_analysis = [] df['EMA20'] = df['Close'].ewm(span=20, adjust=False).mean() df['EMA50'] = df['Close'].ewm(span=50, adjust=False).mean() df['EMA14'] = df['Close'].ewm(span=14, adjust=False).mean() if ( df['EMA14'].iloc[-1] > df['EMA50'].iloc[-1] and df['EMA14'].iloc[-2] < df['EMA50'].iloc[-2] ): ema_analysis.append('golden_cross') elif ( df['EMA14'].iloc[-1] < df['EMA50'].iloc[-1] and df['EMA14'].iloc[-2] > df['EMA50'].iloc[-2] ): ema_analysis.append('death_cross') if ( df['Close'].iloc[-1] > df['Open'].iloc[-1] and df['Open'].iloc[-1] > df['Low'].iloc[-1] and df['High'].iloc[-1] > df['Close'].iloc[-1] ): candle_analysis.append('bullish_engulfing') elif ( df['Close'].iloc[-1] < df['Open'].iloc[-1] and df['Open'].iloc[-1] < df['High'].iloc[-1] and df['Low'].iloc[-1] > df['Close'].iloc[-1] ): candle_analysis.append('bearish_engulfing') if ('golden_cross' in ema_analysis and 'bullish_engulfing' in candle_analysis) or 'lower_band_breakout' in candle_analysis: return 'buy' elif ('death_cross' in ema_analysis and 'bearish_engulfing' in candle_analysis) or 'upper_band_breakout' in candle_analysis: return 'sell' else: return '' - User
OKay, can you add stochastic in this code
- Assistant