I used your code: def signal_generator(df):
    if df is None or len(df) < 2:
        return ''

    df['EMA10'] = df['Close'].ewm(span=10, adjust=False).mean()
    df['EMA20'] = df['Close'].ewm(span=20, adjust=False).mean()

    ema_analysis = []
    candle_analysis = []

    if (
        df['EMA10'].iloc[-1] > df['EMA20'].iloc[-1] and
        df['EMA10'].iloc[-2] < df['EMA20'].iloc[-2]
    ):
        ema_analysis.append('golden_cross')

    elif (
        df['EMA10'].iloc[-1] < df['EMA20'].iloc[-1] and
        df['EMA10'].iloc[-2] > df['EMA20'].iloc[-2]
    ):
        ema_analysis.append('death_cross')

    for i in range(1, len(df)):
        current_candle = df[i]
        previous_candle = df[i-1]
        
        current_open = float(current_candle[1])
        current_close = float(current_candle[4])
        previous_open = float(previous_candle[1])
        previous_close = float(previous_candle[4])
        
        # Check for bullish Engulfing pattern
        if (current_open < previous_open) and (current_close > previous_close):
            candle_analysis.append('bullish_engulfing')
            
        # Check for bearish Engulfing pattern
        elif (current_open > previous_open) and (current_close < previous_close):
            candle_analysis.append('bearish_engulfing')


    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'
    else:
        return ''


end_time = int(time.time() * 1000)
start_time = end_time - lookback * 60 * 1000
    
TradeType = "BUY" or "SELL"

secret_key = API_KEY_BINANCE  # Replace with your actual secret key obtained from MXC Exchange
access_key = API_SECRET_BINANCE # Replace with your actual access key obtained from MXC Exchange

import binance

while True:
    df = get_klines(symbol, interval, lookback)
    # Get current position
    try:
        account = client.account
    except binance.error.ClientError as e:
        print(f"Error getting account information: {e}")
        account = None
        
        # Find position for the desired symbol
        if account is not None:
            positions = account['positions']
            position = None
            for p in positions:
                if p['symbol'] == symbol:
                    position = p['positionAmt']

    if df is not None:
        signals = signal_generator(df)
        print(f"The signal time is: {dt.datetime.now().strftime('%Y-%m-%d %H:%M:%S')} - Signals: {signals}")

        if signals == 'buy':
            try:
                client.new_order(symbol=symbol, side='BUY', type='MARKET', quantity=0.1)
                print("Long order executed!")
            except binance.error.ClientError as e:
                print(f"Error executing long order: {e}")
            time.sleep(1)

            # Set Stop Loss based on position
            if position == 'open':
                stop_loss = df['Open'][-1] * 0.9
            elif position == '+10%':
                stop_loss = df['Open'][-1] * 1.03
            elif position == '>+10%':
                stop_loss = df['Open'][-1]
            else:
                stop_loss = None

            if stop_loss is not None:
                try:
                    # Place Stop Loss order
                    client.new_order(symbol=symbol, side='SELL', type='STOP_MARKET', stopPrice=stop_loss, quantity=0.1)
                    print(f"Stop Loss order placed at {stop_loss}")
                except binance.error.ClientError as e:
                    print(f"Error placing Stop Loss order: {e}")

        if signals == 'sell':
            try:
                client.new_order(symbol=symbol, side='SELL', type='MARKET', quantity=0.1)
                print("Short order executed!")
            except binance.error.ClientError as e:
                print(f"Error executing short order: {e}")
            time.sleep(1)

            # Set Stop Loss based on position
            if position == 'open':
                stop_loss = df['Open'][-1] * 1.1
            elif position == '+10%':
                stop_loss = df['Open'][-1] * 0.97
            elif position == '>+10%':
                stop_loss = df['Open'][-1] * 0.9
            else:
                stop_loss = None

            if stop_loss is not None:
                try:
                    # Place Stop Loss order
                    client.new_order(symbol=symbol, side='BUY', type='STOP_MARKET', stopPrice=stop_loss, quantity=0.1)
                    print(f"Stop Loss order placed at {stop_loss}")
                except binance.error.ClientError as e:
                    print(f"Error placing Stop Loss order: {e}")
    
    time.sleep(1)

But I getting ERROR: Traceback (most recent call last):
  File "C:\Users\Alan\AppData\Roaming\Python\Python311\site-packages\pandas\core\indexes\base.py", line 3652, in get_loc    
    return self._engine.get_loc(casted_key)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pandas\_libs\index.pyx", line 147, in pandas._libs.index.IndexEngine.get_loc
  File "pandas\_libs\index.pyx", line 176, in pandas._libs.index.IndexEngine.get_loc
  File "pandas\_libs\hashtable_class_helper.pxi", line 7080, in pandas._libs.hashtable.PyObjectHashTable.get_item
  File "pandas\_libs\hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 1

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "c:\Users\Alan\.vscode\jew_bot\jew_bot\jew_bot.py", line 188, in <module>
    signals = signal_generator(df)
              ^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\Alan\.vscode\jew_bot\jew_bot\jew_bot.py", line 135, in signal_generator
    current_candle = df[i]
                     ~~^^^
  File "C:\Users\Alan\AppData\Roaming\Python\Python311\site-packages\pandas\core\frame.py", line 3761, in __getitem__       
    indexer = self.columns.get_loc(key)
              ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Alan\AppData\Roaming\Python\Python311\site-packages\pandas\core\indexes\base.py", line 3654, in get_loc    
    raise KeyError(key) from err
KeyError: 1