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

Two EMA initializations with identical new pricesThe green curve continues prior state 100 and gives 104, 106, 107 after prices 108. Violet starts at 108 and stays 108. The differences shrink 4, 2, 1.Same price, different initial state100108t 0t 1t 2t 3104106107Continuation:100→104→106→107Restart at 108:108→108→108Difference after new prices:4→2→1
The dashed line shows the assumed constant price 108. Output differences arise solely from the earlier state.

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.

Same eight closes, explicit SMA seed at bar 5
BarCloseSMA5EMA5
11.0800——
21.0820——
31.0840——
41.0850——
51.09001.0842001.084200
61.08801.0858001.085467
71.08601.0866001.085644
81.08001.0858001.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.