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 # Extract necessary prices from df # Extract necessary prices from df open_price = df.Open.iloc[-1] close_price = df.Close.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 greatest line strategy - buy signal
    if df.EMA10.iloc[-1] > df.EMA50.iloc[-1] and close_price > max(df['EMA10'].iloc[-2], df['EMA50'].iloc[-2]):
        ema_analysis.append('buy')
    
    # EMA greatest line strategy - sell signal
    elif df.EMA10.iloc[-1] < df.EMA50.iloc[-1] and close_price < min(df['EMA10'].iloc[-2], df['EMA50'].iloc[-2]):
        ema_analysis.append('sell')
    
    # Check for bullish candlestick patterns
    if open_price > close_price and previous_open < previous_close and close_price < previous_open and open_price >= previous_close:
        candle_analysis.append('sell')
    
    elif open_price < close_price and previous_open > previous_close and close_price > previous_open and open_price <= previous_close:
        candle_analysis.append('buy')
                               
        # Combine all analysis into final signal
    ema_signal = 'buy' if 'buy' in ema_analysis else 'sell' if 'sell' in ema_analysis else ''
    candle_signal = 'buy' if 'buy' in candle_analysis else 'sell' if 'sell' in candle_analysis else ''
    
    if ema_signal == 'buy' and candle_signal == 'buy':
        return 'buy'
    elif ema_signal == 'sell' and candle_signal == 'sell':
        return 'sell'
    else:
        return ''
    

    But it deosn't give me any proffitable signal , please can you cahnge my EMA lines strategy to more good strategy

  2. Assistant

    Sure, I can help you modify the EMA lines strategy to potentially improve its profitability. Here's an updated version of the code:

    def signal_generator(df):
        # Calculate EMA and MA lines
        df['EMA10'] = df['Close'].ewm(span=10, adjust=False).mean()
        df['EMA50'] = df['Close'].ewm(span=50, adjust=False).mean()
        df['EMA200'] = df['Close'].ewm(span=200, adjust=False).mean()
        df['MA10'] = df['Close'].rolling(window=10).mean()
        df['MA50'] = df['Close'].rolling(window=50).mean()
        df['MA200'] = df['Close'].rolling(window=200).mean()
        
        # Extract necessary prices from df
        open_price = df.Open.iloc[-1]
        close_price = df.Close.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 strategy - buy signal
        if df.EMA10.iloc[-1] > df.EMA50.iloc[-1] and df.EMA10.iloc[-2] <= df.EMA50.iloc[-2]:
            ema_analysis.append('buy')
    
        # EMA crossover strategy - sell signal
        elif df.EMA10.iloc[-1] < df.EMA50.iloc[-1] and df.EMA10.iloc[-2] >= df.EMA50.iloc[-2]:
            ema_analysis.append('sell')
    
        # Check for bullish candlestick patterns
        if previous_open > previous_close and close_price > previous_close:
            candle_analysis.append('buy')
    
        # Check for bearish candlestick patterns
        if previous_open < previous_close and close_price < previous_close:
            candle_analysis.append('sell')
                                   
        # Combine all analysis into final signal
        ema_signal = 'buy' if 'buy' in ema_analysis else 'sell' if 'sell' in ema_analysis else ''
        candle_signal = 'buy' if 'buy' in candle_analysis else 'sell' if 'sell' in candle_analysis else ''
    
        if ema_signal == 'buy' and candle_signal == 'buy':
            return 'buy'
        elif ema_signal == 'sell' and candle_signal == 'sell':
            return 'sell'
        else:
            return ''
    

    In this version, I've modified the EMA strategy to use a crossover approach. It generates a buy signal when the 10-day EMA crosses above the 50-day EMA, and a sell signal when the 10-day EMA crosses below the 50-day EMA. Additionally, I've simplified the candlestick pattern analysis by checking if the current candle is bullish (close price > previous close) or bearish (close price < previous close) compared to the previous candle.

    Please note that no strategy is guaranteed to be profitable, and it's essential to thoroughly backtest and validate any trading strategy before using it with real money.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.