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['EMA14'] = df['Close'].ewm(span=14, adjust=False).mean() ema_analysis = [] candle_analysis = [] if ( df['EMA5'].iloc[-1] > df['EMA14'].iloc[-1] and df['EMA5'].iloc[-2] < df['EMA14'].iloc[-2] ): ema_analysis.append('golden_cross') elif ( df['EMA5'].iloc[-1] < df['EMA14'].iloc[-1] and df['EMA5'].iloc[-2] > df['EMA14'].iloc[-2] ): ema_analysis.append('death_cross') # Check for a bullish engulfing pattern if ( df['Open'].iloc[-1] < df['Close'].iloc[-1] and df['Open'].iloc[-2] > df['Close'].iloc[-2] and df['Open'].iloc[-2] > df['Close'].iloc[-1] ): candle_analysis.append('bullish_engulfing') # Check for a bearish engulfing pattern if ( df['Open'].iloc[-1] > df['Close'].iloc[-1] and df['Open'].iloc[-2] < df['Close'].iloc[-2] and df['Open'].iloc[-2] < df['Close'].iloc[-1] ): candle_analysis.append('bearish_engulfing') # Check for a hammer candlestick if df['Close'].iloc[-1] < df['Open'].iloc[-1] and (df['Open'].iloc[-1] - df['Low'].iloc[-1]) > 2 * (df['Close'].iloc[-1] - df['Open'].iloc[-1]): candle_analysis.append('hammer') # Check for a shooting star candlestick if df['Close'].iloc[-1] > df['Open'].iloc[-1] and (df['Close'].iloc[-1] - df['High'].iloc[-1]) > 2 * (df['Open'].iloc[-1] - df['Close'].iloc[-1]): candle_analysis.append('shooting_star') # Check for a doji candlestick if abs(df['Close'].iloc[-1] - df['Open'].iloc[-1]) <= 0.1 * (df['High'].iloc[-1] - df['Low'].iloc[-1]): candle_analysis.append('doji') 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' elif ('doji' in candle_analysis and 'hammer' in candle_analysis and 'shooting_star' in candle_analysis): return 'additional condition met' else: return ''Can you tell me what I need to change in my code for it can give me signlas for strong entrey ?
- Assistant
To modify the code to generate signals for strong entry, you can add additional conditions based on your specific criteria. Here's an example of how you can enhance the code:
- Add a new list variable for strong analysis signals:
strong_analysis = []- Modify the existing conditions to include strong signals. For example, for the golden cross signal, you can check if the EMA5 is above the EMA14 and the difference between the two EMAs is greater than a certain threshold:
if ( df['EMA5'].iloc[-1] > df['EMA14'].iloc[-1] and df['EMA5'].iloc[-2] < df['EMA14'].iloc[-2] and (df['EMA5'].iloc[-1] - df['EMA14'].iloc[-1]) > threshold ): ema_analysis.append('golden_cross') strong_analysis.append('strong_golden_cross') - User
Can you set in my code best EMA strategy for scalping
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.