Skip to content
All library documents

Choosing EMA and MACD History Lengths for Accurate Updates

Article Quant Q&A · Author: Cheok Yan Cheng

Summary

The document asks how much historical data is needed to calculate the latest exponential moving average or MACD value without processing an entire long history. One response offers a rule of thumb: use roughly twice the indicator’s nominal span as warm-up history, combining the relevant EMA spans for MACD before doubling. It also suggests increasing the history geometrically and comparing successive latest values until they agree to the desired precision.

A second response recommends maintaining the prior EMA value and updating it with each new observation, rather than recalculating the indicator from scratch. These approaches address different needs: warm-up history helps initialize an indicator, while incremental updating avoids repeated full-history calculations. The rule of thumb is not a universal accuracy guarantee; the desired tolerance and indicator parameters matter. The document also notes that practical precision should be judged against price precision and trading costs such as slippage.

Key ideas

  • An EMA’s latest value depends on the history used to initialize it.
  • A rule of thumb is to use about twice the nominal EMA span as warm-up history.
  • For MACD, account for the EMA spans involved when choosing the history length.
  • Compare results using progressively longer histories to assess convergence to a chosen tolerance.
  • An EMA can be updated incrementally using its previous value and the newest observation.

Tags

Full text
# What is the minimum history data size to get an accurate EMA/ MACD for latest history point


# What is the minimum history data size to get an accurate EMA/ MACD for latest history point












Currently, I have history data for 10 years.

Most of the time, I only interested in getting EMA/ MACD for the last history point (means yesterday point). Instead of using entire 10 years history, I would only like to provide N data points, for fast calculation, yet get a reasonable accurate EMA. Currently, here is the way for me to determine how many N data.

```
9 days SMA lookback = 8
9 days EMA lookback = 8
9 days 12/26 MACD lookback = 33

final int scale = 2;
startIndex = historyDataSize - ((lookback + 1) * scale);
for (int i = startIndex; i < historyDataSize; i++) {
    // ...
}
```

I know I can further increase `scale` to get a reasonable good EMA/ MACD outcome. The question is, how large I should increase, for fast calculation purpose, yet reasonable accurate?

## Answer by Chloe (score 4, accepted)

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

I implemented these algorithms just a few months ago! I would just double the number of data points that you need. If you need a 10 day EMA, take 20 data points. For the MACD, you need the EMA, so add them together then double it. Here is the algorithm including an Excel spreadsheet you can compare with:

http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:moving_averages

They claim on their charts to use 200+ days for accuracy, but remember that stock prices only have 2 decimals, and usually 4 significant digits, with a maximum of 4 decimals for penny stocks. So you wouldn't need anything more accurate than 2 decimals most of the time. Slippage would matter more!

If you want to be super accurate, and have a dynamic 'scale' or 'lookback', you can calculate the indicator using increasing 'scale' or exponentially greater history samples (x2, x4, x8, ...) until the different between the final results is within 4 significant digits of each other. Then you would need no more accuracy. You could either do this every time or 'calibrate' it using maybe a year of data for the whole market, and take the average of your 'scale'.

## Answer by LazyCat (score 2)

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

You shouldn't recompute your EMA - just keep its old values, and apply your EMA formula to the last value to update.

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.