Skip to content
All library documents

EMA Inputs for Weekly and Monthly Bars, Lookback, and Missing Data

Article Quant Q&A · Author: jmgonet

Summary

The document explains how to choose observations for an exponential moving average (EMA) on bars longer than one day. It reports that closing prices are a common input: the final trading-day close for a weekly bar and the final trading-day close for a monthly bar. The author matched these settings against charting platforms, while emphasizing that there is no universal standard and that defaults can vary.

It also describes two implementation issues that affected the comparison. A longer EMA lookback may require many prior periods to reduce initialization effects; the account gives a rule of thumb for the sample count. Separately, missing observations in a historical price feed caused discrepancies during circuit-breaker days: one provider omitted dates, while another carried forward the prior value. These findings come from the author’s platform comparisons and data checks, so they illustrate practical pitfalls rather than guarantee identical behavior across software or vendors.

Key ideas

  • Weekly and monthly EMAs commonly use the close of the final trading day in each period.
  • EMA input conventions are not universal, so platform defaults should be checked.
  • A long EMA may need many historical observations to reduce initialization effects.
  • Missing dates and provider-specific handling can create differences between calculated indicators and charting platforms.

Tags

Full text
# When using periods that are not days, what is the usual quote that is used as input into the EMA calculation?


# When using periods that are not days, what is the usual quote that is used as input into the EMA calculation?












My current understanding of the EMA calculation with daily periods is to use as quote the closing price of each day:

- Day 0 - Take the closing price as Q0. EMA = Q0

- Day 1 - Take the closing price as Q1. EMA = Q1 * k + Q0 * (1-k)

- Day 2 - Take the closing price as Q2. EMA = Q2 * k + Q1 * (1-k)

- ...

- Day n - Take the closing price as Qn. EMA = Qn * k + Qn-1 * (1-k)

I executed my algorithm over SPY daily quotes, and I stopped it arbitrarily at August the 5th 2019, to display the EMA9 and EMA21 values. These are my results:

- EMA9: 294.77

- EMA21: 296.24

To validate my algorithm, I compared with the IBKR Trading Workstation, at the same date. Here is a screenshot with the SPY quotes around 5-Aug-2019 in daily candles, and the corresponding EMA9 and EMA21:



- EMA9: 294.8

- EMA21: 296.3

So far so good (except some reading error).

Now, using the same application, I choose weekly candles. As expected, the result is quite different because, although the EMA computation is identical, they're not using the same values as input.



- EMA9: 294.0

- EMA21: 289.6

I am not able to reach the same results in my algorithm. Based on my previous success, I believe my EMA computation is correct, but I'm probably not using the correct quotes Q[0..n].

I've tried several options:

- The mean of closing prices over the week (simple average of 5 closing prices, of Monday to Friday).

- The closing price of the last day of the week (one single closing price, the Friday afternoon).

- The mean of mid points over the week (simple average of (open + close)/2, Monday to Friday).

But none give me the same results as the Trading Workstation application. I've checked other sources, and I've got the impression that they all do it in the same way.

So, this is my question:

- When using periods that are not days, what is the usual quote that is used as input into the EMA calculation?

## Answer by jmgonet (score 2)

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

There are several points to answer this question:

Most usual quote is the closing price

That was my original question. Initially I thought that there is a standard. In his comments, @markleeds pointed me out that there is no such standard. This explains why I couldn't find any satisfactory information in Google.

As I'm using TWS, from Interactive Brokers, I opened a ticket to their support platform, but, as usual, I didn't get any response from them (not even an acknowledgement to the reception of my question).

Then I went to www.investing.com, and checked out one of their interactive charts. There you can set the period length to 1d, 1w or 1M, and add any number of indicators. One of the indicators is the EMA. Now, what's so cool with their chart is that you can configure the indicator and select different input values as quotes (open, close, high, low, typical, median...) and, by comparison, I could establish that Trading Workstation is using the closing price.

My conclusions in that respect are:

- When periods are days, the most usual quote to use as input in EMA calculations (and MACD, and others), is the closing price.

- Consistently, when the period is a WEEK, the usual quote is the closing price the last trading day of the week, most commonly Friday.

- And, when the period is a MONTH, the usual quote is the closing price of the last trading day of the month.

When I say usual I mean that, although there is no standard, two mainstream platform are using the same default configuration, so I believe others are doing the same.

Beware of the number of samples

Once I found out what quote to use as input, I could fix my algorithm and match exactly the charts in TWS. But only for daily periods. So, back to case one. I didn't fix anything.

By reading about approximating the EMA with a limited number of terms in the article Moving average from Wikipedia, I realized that, for keeping a precision better than 99.9% you need k samples or more, where:

- k = 3.45 * (N + 1)

As I'm using EMA9 and EMA21, my worst case is N = 21, so I need 72.45 periods. When periods are days, and having 5 trading days per week, this means going back from August the 5th, 2019 to:

- Sd = 5-Aug-2019 - (73 / 5) * 7 = 23-Apr-2019

And this was OK when using days, because I including the whole 2019 year from January the 1st. But, when using week periods, I need to include at least 73 weeks in the calculation:

- Sw = 5-Aug-2019 - 73 * 7 = 11-Mar-2018

So, my second error was not getting enough samples.

Beware of the 'circuit breakers'

I felt really good having fixed out those two problems, the input quote and the number of samples. I could see now my charts being completely identical to both TWS and investing.com in daily, weekly and monthly periods. As a last test, I compared with the current days, around February, March and April 2020, to see if my charts were correct also during the Coronavirus crisis.

And they weren't.

I couldn't believe this. EMA's mathematic is not that complex, it is not prone to accumulating rounding errors, and I fully tested it with data from 2017, so what on Earth?

By checking sample by sample, I found out that there are 4 trading days missing from the data I downloaded from finance.yahoo.com, all in 2020. Namely:

- March the 28th

- March the 21st

- March the 14th

- and February the 17th

Which are days when circuit breakers kicked in Wall Street. To verify this, I downloaded the same SPY historic data from investing.com and comparing both sources, yahoo and investing, I could see that:

- While yahoo simply removed those days from downloaded data,

- investing.com used the same values from the previous day.

So I replaced the missing data, and then my charts matched completely.

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.