I’m calculating EMAs 20, 50, and 100 for 1m candles using python TA-Lib on the futures testnet. And I see the calculated values off by a big margin from the displayed ones. Any idea why that is?
"""
Calculate EMAs using TA-Lib and determine the current trend.
"""
# Calculate EMAs using TA-Lib
df['EMA20'] = talib.EMA(df['Close'].values, timeperiod=20)
df['EMA50'] = talib.EMA(df['Close'].values, timeperiod=50)
df['EMA100'] = talib.EMA(df['Close'].values, timeperiod=100)
# Get the last values of the EMAs
last_ema20 = df['EMA20'].iloc[-1]
last_ema50 = df['EMA50'].iloc[-1]
last_ema100 = df['EMA100'].iloc[-1]
print(f"EMA20: {last_ema20}, EMA50: {last_ema50}, EMA100: {last_ema100}") # Debugging line
# Fetch initial historical data
candles = client.get_klines(symbol="BTCUSDT", interval=Client.KLINE_INTERVAL_1MINUTE, limit=1000)
df = pd.DataFrame(candles, columns=['Open time', 'Open', 'High', 'Low', 'Close', 'Volume', 'Close time', 'Quote asset volume', 'Number of trades', 'Taker buy base asset volume', 'Taker buy quote asset volume', 'Ignore'])
df['Close'] = pd.to_numeric(df['Close'])