SMA vs EMA: Why Do They React Differently?

Recent AAPL candlesticks with twenty-day simple and exponential moving averages calculated from scratch in Python

In the last lesson, we built an Exponential Moving Average from scratch.

Now we have two ways to summarize recent price:

SMA
and
EMA

They can use the same price data. They can even use the same number, such as 20.

But when you draw them on the same chart, the two lines do not move exactly the same way.

Why?

same prices
+ same period

but

different moving-average lines

The answer is not hidden in the chart.

It is hidden in the weighting rule.

1. Start with What Is the Same

Suppose we calculate both:

SMA 20
EMA 20

Both are built from the same Close-price series.

Both try to smooth the day-to-day movement of price.

And both are calculated from prices that already exist.

Close prices
     ↓
 moving average

Neither line knows tomorrow's price.

So the important difference is not the input.

The important difference is how each method remembers that input.

2. SMA Gives Equal Weight Inside Its Window

For a 5-day SMA, the most recent five Close prices are treated equally.

Price 1 → 20%
Price 2 → 20%
Price 3 → 20%
Price 4 → 20%
Price 5 → 20%

Add them. Divide by five.

Then move the window forward one row and repeat.

inside the window
→ equal importance

outside the window
→ no longer included

This creates a simple and easy-to-read kind of memory.

3. EMA Uses Fading Memory

EMA does not divide its influence equally across one fixed window.

Instead, each new value is updated from:

new price
+
previous EMA

The formula we built in the previous lesson was:

EMA_now
=
alpha × Price_now
+
(1 - alpha) × EMA_previous

The newest price receives fresh weight.

Older prices remain inside the previous EMA, but their influence becomes smaller as more updates happen.

recent information
→ stronger influence

older information
→ fading influence

This is the main reason EMA can react differently from SMA.

4. A Tiny Example Makes the Difference Visible

Imagine price has been quiet:

100
100
100
100
110

The last price suddenly jumps to 110.

The 5-day SMA is:

(100 + 100 + 100 + 100 + 110) / 5
= 102

Now imagine the previous EMA was 100.

For EMA 5:

alpha
= 2 / (5 + 1)
≈ 0.333

So the next EMA is approximately:

0.333 × 110
+
0.667 × 100

≈ 103.33

The new price pulled the EMA farther than it pulled the SMA in this example.

new price = 110

SMA 5 ≈ 102.00
EMA 5 ≈ 103.33

That does not mean EMA is always above SMA.

It means the two calculations respond differently because they assign influence differently.

5. Faster Does Not Mean Better

A line that reacts faster may sound better at first.

But faster response has a tradeoff.

faster response
→ follows recent movement more closely

but also

faster response
→ can react more to short-lived movement

A smoother line may ignore some small movements, but it may also react later when price changes quickly.

So we should not ask:

Which one is better?

Not yet.

First ask:

How are they different?

6. Build Both Moving Averages from Scratch

We can now make the comparison with Python.

For SMA, the logic is:

take the most recent N prices
→ add them
→ divide by N
→ move forward one row

For EMA, the logic is:

calculate alpha
→ combine new price with previous EMA
→ save the new EMA
→ move forward one row

We deliberately build both calculations ourselves.

We do not need rolling().mean(), ewm(), or a technical-analysis library to understand the idea.

7. Full Runnable Python File

Save this file as:

phase3_07_sma_vs_ema.py

Run:

python phase3_07_sma_vs_ema.py

The important lesson functions are:

simple_moving_average()
→ equal weights inside the recent window

exponential_moving_average()
→ fading weights through recursive updates

draw_candlesticks()
→ keeps the original OHLC price visible

draw_chart()
→ puts SMA and EMA on the same price chart

The script also calculates:

EMA_minus_SMA
=
EMA - SMA

This number does not tell us which average is better.

It simply helps us see when the two calculations disagree more strongly.

8. Read the Chart in the Right Order

When the chart opens, begin with the candles.

1. What did price do?
2. Where is SMA 20?
3. Where is EMA 20?
4. Which line turned first?
5. When did the two lines move closer together again?

Around quiet price movement, the two lines may stay fairly close.

Around a faster move, their different weighting rules can become easier to see.

Keep the causal direction clear:

price changes
     ↓
SMA and EMA recalculate
     ↓
the two lines may separate

The lines respond to price. They do not cause the price movement.

9. Same Number Does Not Mean Same Memory

This point is easy to miss.

SMA 20
and
EMA 20

both contain the number 20.

But that does not mean they remember the past in the same way.

SMA 20 uses a hard window:

20 observations inside
→ equal weight

older observation leaves window
→ zero weight

EMA 20 uses fading memory:

new observation
→ stronger influence

older observations
→ influence fades gradually

So the parameter number alone does not fully describe an indicator.

We also need to understand the calculation behind it.

10. Observation Is Not a Trading Rule

You may notice that EMA turns earlier in some places on the chart.

That is an observation.

OBSERVATION
EMA reacted sooner here.

INTERPRETATION
Its weighting rule gave recent prices more influence.

HYPOTHESIS
Maybe a faster average could detect some changes earlier.

UNKNOWN
Would that improve a trading strategy?

The last question cannot be answered from one chart.

It would require a clearly defined rule and a later backtest.

We are not doing that yet.

11. Change One Thing Yourself

Start with:

AVERAGE_DAYS = 20

Then try:

AVERAGE_DAYS = 10

Run the file again.

Then try:

AVERAGE_DAYS = 50

Ask:

Which setting follows price more closely?

When does EMA move away from SMA?

When do the two lines become close again?

Does the longer setting look smoother?

Do not search for the “best” value.

The goal is to understand how the parameter and the weighting rule change the line.

Check Your Understanding

You are ready to move on if you can explain these ideas in your own words:

  • SMA gives equal weight to prices inside its window.
  • EMA gives more influence to recent prices and lets older influence fade.
  • SMA 20 and EMA 20 can use the same price data but still produce different lines.
  • EMA often reacts faster because of its weighting rule.
  • Faster does not automatically mean better.
  • A chart comparison is an observation, not proof of a profitable trading rule.

What You Just Learned

same Close prices
       ↓
  two weighting rules
       ↓
SMA             EMA
 ↓               ↓
equal          fading
weights        weights
       ↓
 different response
       ↓
speed + smoothness + turning behavior

If one idea stays in your head after this lesson, let it be this:

SMA and EMA can start from the same prices and still move differently because they remember the past differently.

We have now learned two ways to summarize price over time.

Before moving on to momentum, the next lesson takes a short historical detour.

We will look at how moving averages developed from statistical smoothing into tools used in market analysis.

After that, Phase 3 will ask a different kind of question:

Instead of asking
"Where is the average?"

what if we ask
"How much did price change?"

That will take us from moving averages into momentum.