Skip to content
All library documents

EMA Initialization and the Influence of Earlier Price Data

Article Quant Q&A · Author: Slartibartfast

Summary

The document explains why a 200-period exponential moving average can differ across software when it is initialized from different amounts of historical data. Unlike a simple moving average, an EMA updates recursively: each new value depends on the previous EMA and the current price, weighted by a smoothing factor. Earlier observations therefore continue to influence the result, though their influence fades over time.

The response clarifies that the EMA period sets the smoothing factor rather than a strict count of observations to include. The questioner reports that a longer history brought their TA-Lib result closer to TradingView, but this is an observation rather than a general rule for matching platforms. Exact agreement can depend on initialization conventions and available price history; the document gives no universal warm-up length or comparison across implementations.

Key ideas

  • An EMA is calculated recursively from the prior EMA and the latest price.
  • Earlier observations can continue to affect an EMA because the calculation has a long memory.
  • The period determines the smoothing factor rather than serving as a strict historical data cutoff.
  • Different initialization and history choices can produce different EMA values across implementations.

Tags

Full text
# How many data point on EMA indicator?


# How many data point on EMA indicator?












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.

## Answer by Yoda And Friends (score 2)

https://quant.stackexchange.com/a/70441

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.

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.