0
$\begingroup$

I am trying to get the same value of EMA as in TradingView but different number of data points are creating different EMA values. Since it is a moving average, 200 is not enough and I have through some trial and error found 535 datapoints are yielding closer results to the 200 ema indicator value in TradingView. Could you please advise how many data points should be used?

I am using a python package called TALIB.

$\endgroup$
1
  • $\begingroup$ Are you familiar with the difference between EMA and MA? EMA is (theoretically) based on all previous datapoints but with decreasing weights. In practice it is computed recursively from the previous value of EMA and the current value of the input. $\endgroup$
    – nbbo2
    Commented Apr 6, 2022 at 10:31

1 Answer 1

2
$\begingroup$

As noob2 pointed out in the comment, EMA is actually using all the previous data points.

Following this page, EMA is calculated recursively:

$\text{EMA}_t = k (P_t - \text{EMA}_{t-1}) + \text{EMA}_{t-1}$

Here, $k \in \mathbb{R}$ is the real parameter of your model. Not the sampling horizon (for the simple MA, the parameter is indeed the number of samples).

You can think to $k$ as the importance you want to give to the most recent price (i.e. how sensitive you want to be to price movements). A trivial idea on how to chose this constant can be found on Investopedia. It is really simple and gives you a clear financial intuition behind this constant.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.