Skip to content
All library documents

Adjusting EMA Smoothing for Intraday Sampling Intervals

Article Quant Q&A · Author: Joe Kalayil

Summary

The document explains how to adapt an exponential moving average (EMA) coefficient when the intended decay period is expressed in days but prices are sampled more frequently. The standard coefficient uses the number of observations in the period; for intraday data, the count of sampling intervals across the full target period replaces the daily observation count.

For an around-the-clock market, the example converts a five-day EMA to five-minute sampling by counting 288 intervals per day and using 1,440 intervals in the coefficient formula. It gives the resulting coefficient as approximately 0.000694, compared with 0.333 for daily sampling. The general relationship is stated in terms of intervals per day and desired EMA duration in days. This assumes equally spaced observations and a continuously trading market; markets with trading sessions, holidays, or irregular sampling require an appropriate interval count. The discussion does not address initialization or other EMA conventions.

Key ideas

  • The EMA coefficient depends on the number of observations represented by the target decay period.
  • For intraday samples, count the sampling intervals across the full desired period before calculating the coefficient.
  • The example assumes a market trading continuously throughout the day.
  • Different sampling frequencies produce different EMA paths even when the decay period is expressed in days.

Tags

Full text
# Calculate Exponential Moving Average for a specific time frame


# Calculate Exponential Moving Average for a specific time frame












I am writing code to calculate and plot the Exponential Moving Average(EMA) for different chart timeframes(tick/1M/5M/1H etc). I found the formula for calculating EMA:

> EMA = Price(t) * k + EMA(y) * (1 – k) Where, t = today, y = yesterday, N = number of days in EMA, k = 2/(N+1)

But I can't figure out how to factor in the timeframe into this formula. I know that the EMA plot looks different for different chart timeframes but I am unable to figure out why it is different.

To summarize with an example:

How would I go about calculating the plot points for the 5-day EMA for a candlestick chart timeframe of 5M, 15M, 1H etc?

Thank you in advance.

## Answer by nbbo2 (score 2, accepted)

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

First, let's assume (hypothetically) you want to compute 5-day EMA from data sampled daily. Then $k_D=2/(N+1)$, here $N=5$, so $k_D=0.333$

Now assume you want to use data sampled every 5 minutes. There are 288 5-minutes intervals in a day (I am assuming a market that trades around the clock). There are 288*5 = 1440 intervals in a 5 day period. So $k_{5m} =2/(288*5+1)=0.000693963$

And similarly you can find the appropriate $k$ to use for other sampling intervals. The general formula is $k=\frac{2}{mN+1}$ where m= number of sampling intervals in a day, N= desired decay period for the moving average in days.

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.