I used your code: def signalgenerator(df): if df is None: return '' df['EMA5'] =…
- User
I used your code: def signal_generator(df): if df is None: return ''
codedf['EMA5'] = df['Close'].ewm(span=5, adjust=False).mean() df['EMA10'] = df['Close'].ewm(span=10, adjust=False).mean() df['EMA5'] = df['Close'].ewm(span=5, adjust=False).mean() df['EMA12'] = df['Close'].ewm(span=12, adjust=False).mean() df['EMA25'] = df['Close'].ewm(span=25, adjust=False).mean() df['EMA200'] = df['Close'].ewm(span=200, adjust=False).mean() df['MA10'] = df['Close'].rolling(window=10).mean() df['MA20'] = df['Close'].rolling(window=20).mean() df['MA50'] = df['Close'].rolling(window=50).mean() df['MA100'] = df['Close'].rolling(window=100).mean() ema_analysis = [] candle_analysis = [] volume_analysis = [] # EMA strategy - buy signal if df['EMA5'].iloc[-1] > df['EMA12'].iloc[-1] > df['EMA25'].iloc[-1]: ema_analysis.append('buy') # EMA strategy - sell signal elif df['EMA5'].iloc[-1] < df['EMA12'].iloc[-1] < df['EMA25'].iloc[-1]: ema_analysis.append('sell') # Candlestick analysis df['Body'] = df['Close'] - df['Open'] df['Range'] = df['High'] - df['Low'] df['UpperShadow'] = df['High'] - df[['Close', 'Open']].max(axis=1) df['LowerShadow'] = df[['Close', 'Open']].min(axis=1) - df['Low'] df['BullishEngulfing'] = (df['Body'] > 0) & (df['Body'].shift() < 0) & (df['Open'] < df['Close'].shift()) df['BearishEngulfing'] = (df['Body'] < 0) & (df['Body'].shift() > 0) & (df['Open'] > df['Close'].shift()) df['Hammer'] = (df['UpperShadow'] >= 2 * df['Body']) & (df['LowerShadow'] <= 0.1 * df['Body']) df['HangingMan'] = (df['UpperShadow'] >= 2 * df['Body']) & (df['LowerShadow'] >= 2 * df['Body']) for i in range(len(df)): if df['BullishEngulfing'].iloc[i]: candle_analysis.append('bullish_engulfing') elif df['BearishEngulfing'].iloc[i]: candle_analysis.append('bearish_engulfing') elif df['Hammer'].iloc[i]: candle_analysis.append('hammer') elif df['HangingMan'].iloc[i]: candle_analysis.append('hanging_man') else: candle_analysis.append('') # Volume strategy df['VolMA20'] = df['Volume'].rolling(window=20).mean() df['VolMA50'] = df['Volume'].rolling(window=50).mean() if df['VolMA20'].iloc[-1] > df['VolMA50'].iloc[-1]: volume_analysis.append('buy') elif df['VolMA20'].iloc[-1] < df['VolMA50'].iloc[-1]: volume_analysis.append('sell') else: volume_analysis.append('') if ('buy' in ema_analysis and 'bullish_engulfing' in candle_analysis and 'buy' in volume_analysis): return 'buy' elif ('sell' in ema_analysis and 'bearish_engulfing' in candle_analysis and 'sell' in volume_analysis): return 'sell' else: return '' - Assistant
I'm sorry to hear that the code provided did not give you the desired results. This code is a basic implementation of a signal generator that combines three analysis techniques: EMA strategy, candlestick analysis, and volume strategy. Keep in mind that trading strategies are complex and require careful consideration of various factors such as market conditions, risk management, and specific trading goals.
It's important to note that no trading strategy guarantees profits, and there are always risks involved in financial markets. The code provided is a simplified version and may not be suitable for all market conditions and assets. I would recommend reviewing and adjusting the strategy based on your specific needs and considering incorporating additional indicators and risk management techniques.
If you have any specific requirements or need assistance with modifying the code or implementing a different strategy, please let me know, and I'll be happy to help.