pandas ta ema calculation not accurate

1.7k Views Asked by At

When using Pandas TA to calculate the EMA, I realized that the EMA does not match the EMA on trading view.

Consider any stock with an EMA of 200. Next, calculate the last EMA with an arbitrary amount of candles. If we pass only 200 candles, the value at that specific time stamp is inaccurate compared to the same time stamp on trading view. Passing 500 candles increases the accuracy significantly. Passing 1000 candles makes the accuracy relatively exact.

Another thing I realized is that the larger your EMA length is, the more candles you will need to get an accurate result. In example, using an EMA of 50 yields a relatively accurate result if using only 200 or so candles.

My question is why are the EMA values inaccurate compared to trading view if you are using the same amount of candles as your EMA length or even double the amount of candles compared to the EMA length? Why does it have to be so much greater?

If anyone wants to test it, I used the Binance exchange with ADAUSDT.

here is my EMA calculation

import pandas as pd
import pandas_ta as ta


def calculate_TA_values(closes, date):
    close_series = pd.Series(closes)
    ema = ta.ema(close_series, 200)
    print(ema)
    print(date)

1

There are 1 best solutions below

0
On

The calcul of EMA is depend to the series you pass as argument,You have to use a longer series as you mentioned and to get the same as Binance or treading view i pass the max 1000 length series then i get the same exact EMA as Binance and Tradingview, i know that takes more time to get data from the api but the mathematical calculation of the EMA is from the beginning of the series.