Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIAi2 WildChat-4.8M (AI2)

I used this signalgenerator code: def signalgenerator(df): Calculate EMA and MA lines…

  1. User

    I used this signal_generator code: 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() # Extract necessary prices from df open_price = df.Open.iloc[-1] close_price = df.Close.iloc[-1] high_price = df.High.iloc[-1] low_price = df.Low.iloc[-1] previous_open = df.Open.iloc[-2] previous_close = df.Close.iloc[-2]

    # Calculate the last candlestick
    last_candle = df.iloc[-1]
    current_price = df.Close.iloc[-1]
    
    # Initialize analysis variables
    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 patterns
    elif last_candle['Close'] > last_candle['Open'] and last_candle.Low > last_candle[['Open', 'Close']].min():
        candle_analysis = 'buy'
    
    # Check for bearish candlestick patterns
    elif last_candle['Close'] < last_candle['Open'] and last_candle.High < last_candle[['Open', 'Close']].max():
        candle_analysis = 'sell'
    
    # Combine all analysis into final signal
    if ema_analysis == 'buy' and candle_analysis == 'buy':
        return 'buy'
    elif ema_analysis == 'sell' and candle_analysis == 'sell':
        return 'sell'
    else:
        return ''
    

    But it doesn't giveing me any signal , please can you change those code : # Combine all analysis into final signal if ema_analysis == 'buy' and candle_analysis == 'buy': return 'buy' elif ema_analysis == 'sell' and candle_analysis == 'sell': return 'sell' else: return '' to this example algorithm : If EMA_analyze giveing signal to buy + candle_analyze giveing signal to buy return buy , or If EMA_analyze giveing signal to sell+ candle_analyze giveing signal to sell return sell else: if EMA_analyze giveing signal to buy + candle_analyze giveing signal to sell return

  2. Assistant

    sell, and if EMA_analyze is giving a signal to sell and candle_analyze is giving a signal to buy return buy.