I used your signalgenerator returning code, but it doesn't return me anything , please…
- User
I used your signal_generator returning code, but it doesn't return me anything , please solve it . Code of signal_generator: def signal_generator(df): # Calculate EMA and MA lines df['EMA5'] = df['Close'].ewm(span=5, adjust=False).mean() df['EMA10'] = df['Close'].ewm(span=10, adjust=False).mean() df['EMA20'] = df['Close'].ewm(span=20, adjust=False).mean() df['EMA50'] = df['Close'].ewm(span=50, adjust=False).mean() df['EMA100'] = df['Close'].ewm(span=100, 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() open = df.Open.iloc[-1] close = df.Close.iloc[-1] previous_open = df.Open.iloc[-2] previous_close = df.Close.iloc[-2] # Calculate the last candlestick # Calculate EMA and MA lines last_candle = df.iloc[-1] current_price = df.Close.iloc[-1]
ema_analysis = '' candle_analysis = '' # EMA crossover - buy signal if df.EMA10.iloc[-1] > df.EMA50.iloc[-1] and current_price > last_candle[['EMA10', 'EMA50']].iloc[-1].min(): ema_analysis = 'buy' # EMA crossover - sell signal elif df.EMA10.iloc[-1] < df.EMA50.iloc[-1] and current_price < last_candle[['EMA10', 'EMA50']].iloc[-1].max(): ema_analysis = 'sell' # EMA crossover - buy signal if df.EMA20.iloc[-1] > df.EMA200.iloc[-1] and current_price > last_candle[['EMA20', 'EMA200']].iloc[-1].min(): ema_analysis = 'buy' # EMA crossover - sell signal elif df.EMA20.iloc[-1] < df.EMA200.iloc[-1] and current_price < last_candle[['EMA20', 'EMA200']].iloc[-1].max(): ema_analysis = 'sell' # Check for bullish trends elif current_price > last_candle[['EMA5', 'EMA20', 'EMA50', 'EMA100', 'EMA200']].iloc[-1].max(): ema_analysis = 'buy' # Check for bearish trends elif current_price < last_candle[['EMA5', 'EMA20', 'EMA50', 'EMA100', 'EMA200']].iloc[-1].min(): ema_analysis = 'sell' # Check for bullish candlestick pattern if (open<close and previous_open>previous_close and close>previous_open and open<=previous_close): candle_analysis = 'buy' # Check for bearish candlestick pattern elif (open>close and previous_open<previous_close and close<previous_open and open>=previous_close): candle_analysis = 'sell' # If there is agreement in both signals if candle_analysis == ema_analysis and ema_analysis != '': return ema_analysis # If there is no agreement in the signals elif candle_analysis != ema_analysis: if candle_analysis == 'buy' and ema_analysis == 'sell': return '' elif candle_analysis == 'sell' and ema_analysis == 'buy': return '' else: return candle_analysis # If no signal is found, return a neutral signal return '' - Assistant
It is possible that the code is not returning anything because there are no signals found based on the current data in your DataFrame. You can try adding print statements to see what the values of each variable are at different points in the code and where the code may be failing to return a signal.
Additionally, you can try running the code on different data to see if it returns a signal. It is also possible that there may be issues with the data itself, such as missing values or incorrect formatting, that are causing the code to fail.
- User
Please change those lines: # If there is agreement in both signals if candle_analysis == ema_analysis and ema_analysis != '': return ema_analysis
# If there is no agreement in the signals elif candle_analysis != ema_analysis: if candle_analysis == 'buy' and ema_analysis == 'sell': return '' elif candle_analysis == 'sell' and ema_analysis == 'buy': return '' else: return candle_analysis # If no signal is found, return a neutral signal return '' - Assistant
Sure, I have made changes to these lines to include more detailed signal analysis as follows:
# If there is agreement in both signals if candle_analysis == ema_analysis and ema_analysis != '': # Check if the current price is above or below the EMA20 line if current_price > df['EMA20'].iloc[-1]: return "Strong Bullish" # Signal for a strong bullish trend else: return "Bullish" # Signal for a bullish trend # If there is no agreement in the signals elif candle_analysis != ema_analysis: # Check if the current price is above or below the EMA20 line if current_price < df['EMA20'].iloc[-1]: return "Strong Bearish" # Signal for a strong bearish trend else: return "Bearish" # Signal for a bearish trend # If no signal is found, return a neutral signal return "No Signal"This updated code not only classifies the trend as bullish, bearish or neutral, but also distinguishes between a strong trend and a regular trend based on the current price's location with respect to the EMA20 line.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.