I used this code: def signalgenerator(df): if df is None or len(df) < 2: return ''…
- User
I used this code: def signal_generator(df): if df is None or len(df) < 2: return ''
df['EMA5'] = df['Close'].ewm(span=5, adjust=False).mean() df['EMA20'] = df['Close'].ewm(span=20, adjust=False).mean() ema_analysis = [] candle_analysis = [] if ( df['EMA5'].iloc[-1] > df['EMA20'].iloc[-1] and df['EMA5'].iloc[-2] < df['EMA20'].iloc[-2] ): ema_analysis.append('golden_cross') elif ( df['EMA5'].iloc[-1] < df['EMA20'].iloc[-1] and df['EMA5'].iloc[-2] > df['EMA20'].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): return 'buy' elif ('death_cross' in ema_analysis and 'bearish_engulfing' in candle_analysis): return 'sell' else: return ''Can you add donchain chanel indicator please
- Assistant
Certainly! Here's an updated version of the code that includes the Donchian Channel indicator:
def signal_generator(df): if df is None or len(df) < 2: return '' df['EMA5'] = df['Close'].ewm(span=5, adjust=False).mean() df['EMA20'] = df['Close'].ewm(span=20, adjust=False).mean() ema_analysis = [] candle_analysis = [] donchian_channel_analysis = [] if ( df['EMA5'].iloc[-1] > df['EMA20'].iloc[-1] and df['EMA5'].iloc[-2] < df['EMA20'].iloc[-2] ): ema_analysis.append('golden_cross') elif ( df['EMA5'].iloc[-1] < df['EMA20'].iloc[-1] and df['EMA5'].iloc[-2] > df['EMA20'].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') # Donchian Channel Indicator dc_high = df['High'].rolling(window=20).max() dc_low = df['Low'].rolling(window=20).min() if df['Close'].iloc[-1] > dc_high.iloc[-1]: donchian_channel_analysis.append('breakout_up') elif df['Close'].iloc[-1] < dc_low.iloc[-1]: donchian_channel_analysis.append('breakout_down') if ('golden_cross' in ema_analysis and 'bullish_engulfing' in candle_analysis and 'breakout_up' in donchian_channel_analysis): return 'buy' elif ('death_cross' in ema_analysis and 'bearish_engulfing' in candle_analysis and 'breakout_down' in donchian_channel_analysis): return 'sell' else: return '' - User
Set doncain chanel to 96 please
- Assistant
Certainly! Here's the updated code with the Donchian Channel set to a period of 96:
def signal_generator(df): if df is None or len(df) < 2: return '' df['EMA5'] = df['Close'].ewm(span=5, adjust=False).mean() df['EMA20'] = df['Close'].ewm(span=20, adjust=False).mean() ema_analysis = [] candle_analysis = [] donchian_channel_analysis = [] if ( df['EMA5'].iloc[-1] > df['EMA20'].iloc[-1] and df['EMA5'].iloc[-2] < df['EMA20'].iloc[-2] ): ema_analysis.append('golden_cross') elif ( df['EMA5'].iloc[-1] < df['EMA20'].iloc[-1] and df['EMA5'].iloc[-2] > df['EMA20'].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') # Donchian Channel Indicator period = 96 dc_high = df['High'].rolling(window=period).max() dc_low = df['Low'].rolling(window=period).min() if df['Close'].iloc[-1] > dc_high.iloc[-1]: donchian_channel_analysis.append('breakout_up') elif df['Close'].iloc[-1] < dc_low.iloc[-1]: donchian_channel_analysis.append('breakout_down') if ('golden_cross' in ema_analysis and 'bullish_engulfing' in candle_analysis and 'breakout_up' in donchian_channel_analysis): return 'buy' elif ('death_cross' in ema_analysis and 'bearish_engulfing' in candle_analysis and 'breakout_down' in donchian_channel_analysis): return 'sell' else: return ''
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.