# Calculating EMA from minute bars

This seems like a rather ignorant question but some searching has proven fruitless. When looking at any EMA lines in a small timeframe (1-minute or 5-minute bars), I noticed the EMA changes across those periods (as expected given the name).

My noob understanding of something like 9EMA is factoring the close value of the previous 9 days. That makes sense.

What is the formula for that concept but using minute bars?

• Is it comparing the current minute close value to the same minute the previous 9 days?
• Or is it a simple average of all the closing values from the day so far and the final close of the previous 8 days?
• Or even more complex... the average of each minute close, each day.

This feels laughable... I'm sure I'm overcomplicating this.

My noob understanding of something like 9EMA is factoring the close value of the previous 9 days. That makes sense.

You're close. This is true for a 9-day SMA specifically. The 9 in a 9 S/EMA can be 9 of any time unit. Whatever unit a single bar is in your chart (the "Period"), that's what will be used. So if you want a 9-day EMA, you'd choose a:

• Length = 9 and
• set your Period to be Days

Length = 9 Period = Day What is the formula for that concept but using minute bars?

It's exactly the same, except discrete close data is taken every minute instead of every day.

`````` EMA(t) = Price(t)×k – EMA(t–1)×(1 – k)

where k = 2 / (N+1)

N = 9 in your example
``````

Notice that this is weighted more heavily toward the most recent time data compared to prior time data. This makes the EMA more of a leading indicator than the SMA (or, rather, less of a lagging indicator).

Also note that it's recursive in nature.

Is it comparing the current minute close value to the same minute the previous 9 days?

No. If you're looking at the minute chart, your Period is a Minute. A 9 EMA would most strongly be influenced by the price 1 minute ago, 2 min ago, 3 min ago, and with each minute before having less and less impact. Price from 2 days ago, let alone 9, has no bearing on a 9 1min EMA.

Or is it a simple average of all the closing values from the day so far and the final close of the previous 8 days?

You're overcomplicating it. The previous days have no significance on a 9 1min EMA. The last 8-9 minutes are the only things that are important.

In the event that you want the last several days to be relevant, you should switch to a 9 Day EMA or a 50 4hr EMA.

Or even more complex... the average of each minute close, each day.

If your Period is a Minute, then in order to account for every minute of the last 9 trading days, your length would have to be:

• Length = 4050, because there are 7.5 hrs / day and 60 min / hr

But no one trades like this.

The formula for calculating an EMA is:

EMA = Price(t) * k + EMA(y) * (1 – k)

t = today, y = yesterday, N = number of days in EMA, k = 2/(N+1)

To calculate a 9 day EMA:

1. Determine k: 2/(9 + 1) = 0.20

2. Add the prices for first 9 days and divide by 9 (9 day SMA)

3. On day 10, multiply the day 10 value by k and multiply the previous day’s moving average by (1-k). Adding the two values gives you the EMA for period 10.

4. Repeat step 3 for every subsequent value.

This formula is the same for whatever periodicity of data your are using (one minute, five minute, daily, etc.).