In this article
After this article, you can
- Explain different EMAs despite identical new prices.
- Check history and initialization before comparing platform outputs.
Terms at hand: Exponential Moving Average (EMA) · Simple Moving Average (SMA) · Stop loss · Take profit (TP)
SMA and EMA are two ways to average a price series. Reproduce a few values before comparing the lines: differences can come from the method, data or initialization. This introduction explains the calculation rather than assigning preset trading jobs to EMA20, EMA50 or SMA200.
Restarting EMA is not continuing it
Assume EMA new-price weightα=0.5. One worksheet has prior state 100; the other starts from current price 108. The next three closes are also 108. The first output rises 104→106→107; the second stays 108.
Scroll sideways to see the full diagram
The update is E′=E+0.5×(108−E). Each new step halves the difference. If EMAs disagree, check where history starts and how the first value is initializedbefore looking for a different formula.
Assumptions: Arbitrary prices and states; α=0.5 explicitly assumed. Two initializations are compared, not recommended configurations or a specific platform's behaviour. Formula or data reference: Fidelity: EMA recursion.
SMA and EMA: define the calculation and its start
For N selected closes, SMA(t) = [C(t) + C(t−1) + … + C(t−N+1)]/N. Each included observation has weight 1/N. When a new close enters, the oldest leaves; adding a sixth value without removing the first is not SMA5.
Here EMA uses α = 2/(N + 1) and E(t) = E(t−1) + α[C(t) − E(t−1)]. Initialize E at bar N with the mean of the first N closes. Fidelity describes an initial SMA; TA-Lib 0.6.4 implements this seed under default compatibility. Other histories or seed conventions can produce different states.
Our eight hypothetical EUR/USD closes are 1.0800,1.0820,1.0840,1.0850,1.0900,1.0880,1.0860,1.0800. They are not observations from a real session. With N = 5, α = 1/3; retain full intermediate precision and display six decimals.
| Bar | Close | SMA5 | EMA5 |
|---|---|---|---|
| 1 | 1.0800 | — | — |
| 2 | 1.0820 | — | — |
| 3 | 1.0840 | — | — |
| 4 | 1.0850 | — | — |
| 5 | 1.0900 | 1.084200 | 1.084200 |
| 6 | 1.0880 | 1.085800 | 1.085467 |
| 7 | 1.0860 | 1.086600 | 1.085644 |
| 8 | 1.0800 | 1.085800 | 1.083763 |
At bar 5, the sum is 5.4210 and the mean 1.0842. SMA5 equals our first EMA5 by construction. Five closes alone do not establish a different EMA without an earlier state or another initialization. At bar 6, the new SMA sum is 5.4290. EMA becomes 1.0842 + (1.0880 − 1.0842)/3 ≈ 1.085467; using 0.33 in place of 1/3 changes the calculation.
Four different questions about a line
1. Did the latest Close rise?
At bar 7, Close falls from 1.0880 to 1.0860, while EMA rises to about 1.085644: the new Close is still above the prior EMA. The sign of Close(t) − Close(t−1) need not equal the sign of the EMA update. Candle colour instead compares that candle’s Open and Close.
2. What left the SMA window?
Subtract adjacent SMA formulas: SMA(t) − SMA(t−1) = [C(t) − C(t−N)]/N. For a second hypothetical path 90,110,100,100,100,100, SMA5 starts at 100 on bar 5 and becomes 102 on bar 6. Initialize EMA5 to 100 at bar 5: it stays 100. SMA rose by (100 − 90)/5 = 2 because 90 left, even though the latest two closes did not change.
3. Which observation is the price above?
Price relative to a mean, a mean’s slope and a crossing of two means are different conditions. A separately defined level of support or resistance is another observation, not proof that the average’s crossing is profitable.
4. Was the bar closed?
A Close-based average can change while a bar is open. A rule using the final Close waits for that value to be known. An intrabar alert and a closed-bar test use different information; do not silently substitute one for the other.
Record the configuration before comparing platforms
MetaQuotes iMA separates symbol, timeframe, averaging period, horizontal shift, method and applied price. Record these, the provider, candle time zone, available history and initialization. The text EMA5 alone does not identify the complete calculation. A median price is not a Close, and a shifted line appears under a different bar.
Match one closed-bar SMA first: check its exact input prices and timestamps. Then compare EMA’s initial state and updates. Missing observations are not zero prices. A longer platform history may provide a different prior state from an eight-row worksheet.
Periods count observations, not trading styles
SMA20 on H1 uses twenty hourly bars: 1,200 quoted minutes if each represents a full hour. Market closures can extend calendar time. SMA200 on M5 represents 1,000 quoted minutes, or 16 hours 40 minutes under the same assumption, not necessarily yesterday’s session. The same period on D1 aggregates different observations.
A value of 9,20,50 or 200 does not assign a compulsory entry, exit or trend role. Specify the complete rule separately, including stop loss and take profit. When using different intervals, preserve when each observation became available; the multi-timeframe analysis article develops that question.
Crossings describe a relation between two computed values
A common golden-cross convention uses a 50-period average crossing above a 200-period average; death cross reverses that relation. Specify the methods, input series, interval and equality convention. For a strict upward crossing, one possible rule is previous fast ≤ slow and current fast > slow.
The crossing is calculated from available input and state. It does not confirm a future market regime, compulsory trade direction or subsequent weeks of returns. A sample of crossings is not a strategy until entries, exits, costs and timing are defined.
Practical takeaway: Match input values, timestamps, weights and initialization before interpreting a difference between lines.
Precision changes the result
Round the displayed result, not the state used by the next update. A last-digit difference may be formatting; a larger one needs input-by-input investigation. For the eight-bar example, do not replace the unrounded bar-8 EMA with 1.083763 before continuing the worksheet.
For EMA20, α = 2/21. An input k completed updates back has coefficient α(1 − α)ᵏ: about 9.5238% now, 8.6168% one bar back, 3.5007% ten back and 1.2868% twenty back. The remaining initial-state coefficient after m updates is (1 − α)ᵐ. This decomposition does not prove more or fewer profitable signals.
Which formula answers your intended question?
SMA discards the observation that leaves its finite window. EMA retains a decaying prior state. If that distinction is clear, define the intended use and evaluate the whole rule on unused data with costs. Neither frequent popularity claims nor a fixed one-month freeze certifies a period as better.
Our controlled examples show arithmetic behaviour, not observed market advantages. At bar 8 both means fall; at bar 7 EMA rises despite a falling Close; in the 90→100 window example SMA rises while price and EMA remain flat. There is no universal “EMA always turns earlier” conclusion.
Reproduce one more row
Add a ninth hypothetical Close of 1.0840. SMA5 now uses bars 5–9: (1.0900 + 1.0880 + 1.0860 + 1.0800 + 1.0840)/5 = 1.085600. Continuing the unrounded bar-8 state with α = 1/3 gives EMA5 ≈ 1.083842. Neither must equal the current Close.
The diagram’s separate example starts from EMA states 100 and 108 with α = 0.5 and identical new prices 108. Differences become 4,2,1. The quiz asks about two updates of an initial difference 8: 8×0.5×0.5 = 2. Reproducing these rows explains why identical recent prices need not immediately reconcile two worksheets.
Continue with the complete guide to moving averages to compare further weighting methods. The technical-analysis section provides related reading. Add a line only after defining the question it should answer.
Check your understanding
One short exercise
About 2 min · you can try again
Two EMA states differ by 8, α=0.5, and both receive the same two new prices. What is their difference after two updates?
- 8, because prices are identical.
- 4.
- 2.
Check the answer and explanation
2.
8×0.5×0.5=2. New prices alone cannot reconcile outputs without accounting for initial state.
Frequently asked
Why is the first EMA equal to SMA in the table?
We initialize EMA5 at bar 5 using the mean of the first five closes, 1.0842. Later rows update that state with α = 1/3. A different seed or earlier history can give another EMA; five closes alone do not imply a different first-price initialization.
Can I use 0.33 instead of 1/3?
It is an approximation that changes the calculation. Use 2/(5 + 1) and retain full state precision. Round only for display; entering a rounded result into the next row produces a different recurrence.
Does a rising EMA mean the latest candle rose?
No. In the model, bar 7’s Close falls relative to the preceding Close, but is still above the prior EMA, so EMA rises. Candle colour compares that candle’s Open and Close, which is a third condition.
Which average is best for entries?
The formula alone does not decide. Define the complete rule, data and information timing, then evaluate net outcomes on data not used to choose parameters. A 200-period line’s claimed popularity, a one-month wait or an extra indicator does not prove better entries.
Sources & bibliography
-
Investopedia EMA vs SMA Comparison · Compares the definitions and behavior of simple and exponential moving averages. www.investopedia.com ↗
-
CFA Institute CFA Institute research portal · The CFA Institute research portal provides access to investment research. www.cfainstitute.org ↗
-
StockCharts Moving Averages — Simple and Exponential · Educational explanations of simple and exponential moving averages. chartschool.stockcharts.com ↗
-
Prentice Hall Press John J. Murphy — Technical Analysis of the Financial Markets (1999) · Publisher description and edition metadata only; the full book text was not read for this review and no verbatim quotation is verified by this link. www.penguinrandomhouse.com ↗
-
Fidelity Simple Moving Average (SMA) · Defines a finite-period arithmetic mean. Common educational uses do not demonstrate market-wide order concentration or a profitable trading rule. www.fidelity.com ↗
-
TA-Lib EMA implementation, version 0.6.4 · Pinned code distinguishes the default SMA seed from an alternative initial price and shows the recursive update. The article uses an explicit seed, not every platform’s configuration. raw.githubusercontent.com ↗
-
MetaQuotes MQL5 Reference — iMA parameters · Separates symbol, timeframe, averaging period, shift, method and applied price. EMA5 alone is not a complete specification. www.mql5.com ↗
