Exponential Moving Average (EMA): Formula, Settings, and EMA vs. SMA

Two moving-average curves respond differently to the same changing price path.

Key takeaways

  • EMA gives more weight to recent closes but keeps a decaying influence from older prices; its period does not describe a fixed window.
  • A faster average does not guarantee a busier trading rule: the distance required before acting can change the comparison with SMA.
  • Matched historical tests distinguish responsiveness, transaction activity, and investment results; none is a substitute for the others.

An Exponential Moving Average (EMA) smooths prices while giving more weight to recent observations. It is commonly compared with the Simple Moving Average (SMA), which gives equal weight to every close in its window.

EMA is often described as faster. That is useful shorthand for how it responds to a fresh price change, but it does not tell you how often a complete trading rule will act. We examined 97,216 historical configuration evaluations, then added 6,272 fixed-amount activity controls, to separate the weighting calculation from the decision rule built around it.

How EMA is calculated

The usual EMA update is:

alpha = 2 ÷ (length + 1)
EMA now = alpha × close now + (1 − alpha) × EMA previously

For EMA 20, alpha is 2/21, or about 9.52%. Each new close supplies that fraction of the updated average; the previous EMA supplies the rest. SMA 20 instead gives each of its latest 20 closes a 5% weight. TradingView’s moving-average reference describes these calculations.

Initialization matters near the beginning of a series. Different chart packages can start the recursion differently, so two EMA lines may briefly disagree even when they use the same update formula.

The length follows the chart’s candles. An EMA 20 on an hourly chart and an EMA 20 on a daily chart use the same weighting rule over very different elapsed time.

EMA 20 keeps some history older than 20 candles

SMA 20 drops a close completely when it leaves the window. EMA 20 keeps multiplying that close’s influence by 19/21 as new candles arrive. Its influence becomes small rather than disappearing at a fixed age.

Constructed teaching example More weight at the front, with a longer tail

EMA puts almost twice as much weight on the latest close as SMA 20, while keeping a small influence from closes older than 20 candles.

The value table below is available without JavaScript.

Chart data
Data and calculation details
Source: Calculated EMA20 and SMA20 weight profiles. EMA uses alpha = 2/21 and weight alpha × (1 − alpha)^age. SMA assigns 1/20 to ages 0–19 and zero afterward. EMA has an infinite tail; displayed ages 0–59 omit the remaining 0.247% weight. These are mathematical weights, not market prices or executions. Constructed values illustrate the calculation; they are not market history or backtest results.
Accessible value table (60 observations)
ObservationWeight on each closing price (%) · EMA20Weight on each closing price (%) · SMA20
09.5245.000
18.6175.000
27.7965.000
37.0545.000
46.3825.000
55.7745.000
65.2245.000
74.7275.000
84.2765.000
93.8695.000
103.5015.000
113.1675.000
122.8665.000
132.5935.000
142.3465.000
152.1225.000
161.9205.000
171.7375.000
181.5725.000
191.4225.000
201.2870.000
211.1640.000
221.0530.000
230.9530.000
240.8620.000
250.7800.000
260.7060.000
270.6390.000
280.5780.000
290.5230.000
300.4730.000
310.4280.000
320.3870.000
330.3500.000
340.3170.000
350.2870.000
360.2590.000
370.2350.000
380.2120.000
390.1920.000
400.1740.000
410.1570.000
420.1420.000
430.1290.000
440.1160.000
450.1050.000
460.0950.000
470.0860.000
480.0780.000
490.0710.000
500.0640.000
510.0580.000
520.0520.000
530.0470.000
540.0430.000
550.0390.000
560.0350.000
570.0320.000
580.0290.000
590.0260.000

With the standard formula, roughly 13.51% of EMA 20’s total weight lies on closes at least 20 candles old. Its latest close receives more weight than SMA 20’s latest close, while its older tail remains present.

There is another useful consequence. Both SMA 20 and the established EMA 20 have a weighted average observation age of 9.5 candles. On a perfectly steady linear price rise, both therefore settle at the same distance behind price. They respond differently when the path bends or becomes noisy. “Faster” describes a response pattern; it is not a fixed number of candles saved on every market move.

Common EMA settings and signals

Shorter settings such as 9 or 20/21 emphasize recent movement. Settings such as 50 and 200 describe broader trends. These numbers are conventions, and none defines a universally best trade.

Common uses include:

  • Price relative to EMA: price above the average supplies upward trend context; price below supplies downward context.
  • EMA slope: a rising or falling line describes how the smoothed price is changing.
  • Two-average crossovers: a shorter EMA moving above or below a longer one changes their relative ordering.
  • Pullbacks toward EMA: traders watch how price behaves near the line during a trend.

Fidelity’s EMA guide explains these trend and support/resistance interpretations. The line remains a summary of historical prices. A touch or crossing does not establish that a reversal will follow.

Our controlled experiment focuses on price relative to one average. It does not test every crossover or pullback method described above.

The distance before acting changes the result

We compared otherwise identical long-only rules using SMA or EMA at the same length:

No buffer: buy above the average; exit below it.
With buffer: buy above average × (1 + buffer).
             exit below average × (1 − buffer).

A 2% buffer means 2% above the average for entry and 2% below for exit. This is a fixed percentage band, rather than a standard-deviation band. The gap between entry and exit reduces reactions to small movements around the line.

Recorded backtest metrics The decision band changes the SMA–EMA comparison

Compare the same length with and without a symmetric 2% decision band. One execution is one buy or sell.

The value table below is available without JavaScript.

Chart data
Data and calculation details
This view selects a representative example; the chart-data download retains the full comparison. Source: TrainBard matched SMA/EMA activity controls. Every point changes only average length. Buffer is symmetric: enter above the upper band, exit below the lower band. Fixed quote controls request qty = 100 / signal close to reduce funding failures; these are recorded executions, not an inferred mathematical signal count. Complete eight-frame curves and the separate 99% allocation study are in the evidence download.
Accessible value table (196 observations)
ObservationRecorded executions · small fixed amount · SMA · no bufferRecorded executions · small fixed amount · EMA · no bufferRecorded executions · small fixed amount · SMA · 2% bufferRecorded executions · small fixed amount · EMA · 2% buffer
53,732.0003,626.000205.000112.000
63,376.0003,284.000250.000129.000
73,108.0003,042.000265.000147.000
82,802.0002,830.000269.000169.000
92,597.0002,672.000277.000183.000
102,395.0002,502.000287.000189.000
112,289.0002,360.000296.000205.000
122,151.0002,280.000296.000205.000
132,019.0002,172.000302.000203.000
141,933.0002,090.000300.000209.000
151,837.0002,002.000296.000210.000
161,777.0001,934.000292.000212.000
171,735.0001,882.000280.000220.000
181,719.0001,792.000270.000222.000
191,662.0001,732.000266.000222.000
201,622.0001,674.000262.000214.000
211,614.0001,636.000258.000216.000
221,548.0001,600.000248.000212.000
231,510.0001,554.000246.000208.000
241,466.0001,528.000244.000208.000
251,448.0001,474.000242.000208.000
261,406.0001,412.000242.000208.000
271,376.0001,374.000240.000206.000
281,338.0001,366.000240.000202.000
291,326.0001,332.000240.000200.000
301,292.0001,312.000234.000202.000
311,242.0001,276.000230.000198.000
321,208.0001,254.000228.000198.000
331,150.0001,220.000226.000198.000
341,124.0001,178.000224.000196.000
351,122.0001,160.000216.000194.000
361,102.0001,142.000214.000194.000
371,052.0001,128.000216.000194.000
381,014.0001,108.000214.000192.000
391,006.0001,082.000206.000190.000
401,006.0001,066.000202.000186.000
411,004.0001,034.000202.000186.000
421,006.0001,028.000202.000186.000
431,004.0001,030.000194.000182.000
44976.0001,002.000194.000182.000
45996.000986.000192.000182.000
46982.000994.000186.000178.000
47974.000982.000184.000178.000
48964.000964.000184.000178.000
49940.000968.000180.000174.000
50934.000976.000176.000174.000
51908.000960.000174.000172.000
52894.000932.000174.000174.000
53888.000916.000176.000172.000
54880.000910.000176.000172.000
55866.000904.000180.000172.000
56856.000892.000178.000170.000
57842.000884.000180.000170.000
58844.000870.000176.000168.000
59828.000862.000174.000168.000
60810.000850.000168.000170.000
61808.000834.000164.000170.000
62814.000830.000164.000168.000
63818.000836.000162.000166.000
64810.000820.000162.000166.000
65806.000820.000160.000166.000
66804.000816.000158.000164.000
67808.000806.000158.000162.000
68804.000814.000158.000162.000
69808.000802.000154.000158.000
70802.000784.000154.000158.000
71798.000780.000152.000158.000
72804.000784.000150.000160.000
73792.000778.000150.000160.000
74778.000772.000152.000158.000
75766.000760.000152.000156.000
76750.000750.000154.000150.000
77744.000754.000152.000150.000
78742.000744.000152.000150.000
79732.000746.000152.000146.000
80728.000738.000148.000146.000
81730.000726.000148.000146.000
82726.000712.000146.000144.000
83698.000704.000146.000142.000
84686.000696.000146.000142.000
85692.000696.000146.000142.000
86674.000698.000150.000146.000
87678.000694.000146.000146.000
88676.000692.000146.000142.000
89682.000680.000148.000142.000
90680.000672.000146.000142.000
91676.000666.000146.000142.000
92668.000670.000142.000142.000
93660.000672.000142.000140.000
94678.000674.000140.000140.000
95660.000672.000142.000138.000
96648.000654.000142.000142.000
97652.000646.000142.000142.000
98652.000640.000142.000140.000
99640.000632.000142.000138.000
100636.000624.000142.000136.000
101620.000628.000140.000136.000
102626.000630.000138.000134.000
103618.000640.000140.000134.000
104596.000640.000140.000134.000
105604.000648.000140.000132.000
106602.000636.000138.000132.000
107590.000636.000136.000128.000
108590.000628.000136.000128.000
109586.000626.000136.000124.000
110584.000610.000136.000124.000
111594.000614.000136.000124.000
112588.000608.000134.000124.000
113578.000604.000134.000124.000
114580.000604.000134.000124.000
115572.000600.000132.000124.000
116580.000604.000130.000120.000
117570.000600.000130.000118.000
118568.000608.000130.000118.000
119560.000612.000128.000116.000
120572.000618.000126.000116.000
121582.000614.000122.000116.000
122570.000602.000122.000116.000
123570.000594.000120.000116.000
124564.000584.000120.000116.000
125566.000586.000118.000116.000
126558.000580.000118.000116.000
127562.000578.000116.000116.000
128564.000572.000112.000116.000
129570.000578.000112.000114.000
130570.000568.000112.000114.000
131576.000564.000112.000114.000
132560.000566.000114.000110.000
133574.000568.000114.000110.000
134574.000574.000114.000110.000
135566.000588.000114.000110.000
136568.000590.000114.000110.000
137558.000580.000114.000110.000
138550.000582.000110.000110.000
139530.000584.000110.000108.000
140532.000586.000110.000108.000
141526.000586.000110.000106.000
142522.000592.000108.000104.000
143514.000592.000112.000104.000
144508.000580.000114.000104.000
145492.000568.000114.000104.000
146494.000558.000114.000102.000
147488.000556.000112.000100.000
148492.000550.000112.00096.000
149510.000544.000110.00096.000
150498.000542.000110.000100.000
151496.000532.000110.000100.000
152482.000524.000110.000102.000
153474.000528.000110.000100.000
154472.000532.000108.000100.000
155460.000524.000108.000100.000
156458.000516.000104.000100.000
157462.000510.000102.000100.000
158456.000512.000102.000100.000
159446.000496.000102.000100.000
160436.000492.000102.000100.000
161428.000494.000104.000100.000
162434.000486.000104.00096.000
163438.000486.000102.00094.000
164426.000490.000102.00094.000
165422.000480.000100.00094.000
166422.000468.000100.00094.000
167420.000476.00098.00094.000
168430.000484.00098.00094.000
169430.000486.00098.00096.000
170422.000484.00098.00096.000
171420.000484.00098.00096.000
172428.000492.000100.00096.000
173438.000486.000100.00094.000
174432.000486.00098.00094.000
175432.000482.00098.00090.000
176434.000474.00098.00090.000
177436.000462.00098.00090.000
178432.000454.00098.00090.000
179428.000450.00096.00090.000
180428.000446.00094.00090.000
181422.000444.00094.00090.000
182420.000438.00094.00090.000
183420.000438.00092.00090.000
184414.000434.00092.00090.000
185420.000432.00092.00090.000
186422.000418.00090.00090.000
187412.000416.00090.00090.000
188406.000408.00090.00090.000
189408.000414.00090.00090.000
190408.000412.00090.00090.000
191396.000410.00092.00090.000
192394.000408.00092.00088.000
193390.000406.00094.00088.000
194382.000398.00094.00088.000
195380.000398.00094.00088.000
196368.000396.00094.00088.000
197370.000402.00096.00088.000
198368.000396.00092.00088.000
199366.000400.00092.00088.000
200372.000400.00092.00088.000

Each point holds the rule and band fixed and changes only the average length. One execution means one buy or one sell. The displayed activity control uses a small fixed amount to reduce the funding effects that can interrupt orders under near-full allocation.

In the displayed comparison, EMA recorded more executions than SMA at 166 of 196 lengths with no buffer. At a 2% buffer, EMA recorded fewer executions at 163 lengths. This was a change across a broad set of neighboring lengths, rather than a single selected setting.

Across all eight historical comparisons, EMA was busier for a majority of lengths with no buffer. With the 2% buffer, it was quieter for a majority in six of eight. The other two retained a busier EMA majority. The decision band changed the comparison frequently, without making the outcome uniform.

The mechanism is worth keeping in view. An EMA can follow a move more closely, leaving price short of the percentage entry hurdle even when it is far enough from the SMA to qualify. Reacting more strongly to recent prices does not guarantee more completed entry-and-exit cycles. The result depends on the price path, period, and decision distance together.

Fewer transactions do not establish a better investment

A wider band can skip a false crossing, enter a trend later, or miss part of it entirely. Changing the smoother can improve a historical return in one setting and worsen it in another.

The broad study therefore retains return, fees, and platform-reported drawdown alongside activity. It is not a contest decided by the quietest line or the highest single return. The fixed-amount controls isolate activity under a different allocation; their low-exposure returns are not comparable with the main strategy’s returns.

For practical research, write the whole rule before comparing averages: price source, length, entry distance, exit distance, order timing, and allocation. Then compare those same rules across different historical conditions. The label “EMA” supplies only one part of that specification.

Try the tested rule

The defaults use EMA 50 with a 0.5% symmetric buffer. Set smoothing to 0 for the matched SMA rule. The script requests 99% equity sizing and a 500-candle startup; set fees and market dates separately in the backtest settings.

Pine Script v6
Open editor

//@version=6
strategy("EMA sensitivity laboratory", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=99, process_orders_on_close=false)
length = input.int(50, "Length", minval=2)
buffer = input.float(0.5, "Symmetric buffer percent", minval=0)
smoothing = input.int(1, "Smoothing: 0 SMA, 1 EMA", minval=0, maxval=1)
s = ta.sma(close, length)
e = ta.ema(close, length)
maValue = smoothing == 0 ? s : e
upper = maValue * (1 + buffer / 100)
lower = maValue * (1 - buffer / 100)
if bar_index >= 500
    if strategy.position_size > 0 and close < lower
        strategy.close("Long")
    else if strategy.position_size == 0 and close > upper
        strategy.entry("Long", strategy.long)
plot(maValue, title="Average", color=color.blue)
plot(upper, title="Entry band", color=color.green)
plot(lower, title="Exit band", color=color.orange)
Study design, complete comparisons, and execution limits

The main grid contains lengths 5–200 by 1, symmetric buffers 0–3% by 0.1 percentage point, and two smoothers. That is 12,152 settings per frame × eight frames = 97,216 configuration evaluations. These are related settings, not independent statistical trials.

The frames are Binance Spot BTCUSDT and ETHUSDT, 2h and 4h candles, and windows 2021-01-01–2023-12-31 and 2024-01-01–2025-12-31, with UTC date endpoints. Date-only endpoints are candle-open boundaries: the final supplied candle opens at 00:00 UTC on the listed end date, rather than covering that entire calendar day. The earlier window guided exploration; the unchanged script and grid were carried across the other frames. All are retrospective comparisons. Earlier projects had already exposed these historical periods, so the later window is not a blind holdout.

Every main run starts with 10,000 USDT cash, requests 99% equity allocation, has no leverage or cash yield, and uses 0.1% combined fee/slippage per execution. A persistent 1% cash reserve is not guaranteed by the recorded fill model. Flat-position guards prevent repeated entry requests while a position is held. A close beyond the relevant band requests a market order for the following candle; gaps, fees, and available cash can affect fills.

The first 500 candles are a common startup inside each selected window. EMA 200 still retains about 0.67% of its initial-state influence after 500 updates; startup reduces initialization effects without proving exact convergence. Identical candle counts represent different elapsed time on the two candle sizes.

The additional 6,272 activity evaluations repeat all 196 lengths at buffers 0 and 2% for both smoothers across all eight frames, using quantity 100 / close at the signal candle. This requests an amount near 100 USDT; the following open can change its realized value. A separate 32-row set checks length 50 at buffers 0 and 0.5% under the same small-amount sizing. These controls and the detailed default trace are excluded from the 97,216 main count. The displayed activity panel is the earlier BTCUSDT 2h fixed-amount control; the downloadable chart retains three representative panels, and the complete eight-frame profiles remain in the evidence file.

Main results were collected through TrainBard’s MCP and web interface. Every original export was preserved and checked against its exact requested parameter grid. Browser exports were also reconciled with visible completion, zero-trade, error, cost and date settings. A separate four-row interface comparison matched every common numeric metric exactly and is excluded from the main count. No failed or duplicate tuples were accepted. Recorded execution counts can still reflect the platform’s funding model; fixed-amount controls reduce that confound without turning the observations into a universal signal-count theorem. Batch metrics have slightly lower numerical precision than detailed runs.

The compact study evidence preserves all frame definitions, run identifiers, result checksums, paired comparisons, selected rows, and complete activity profiles. The shared execution and source audit records same-start passive benchmarks, fill/fee controls, and candle checks. Returned historical series can differ slightly from exchange monthly archives, so the exact run candles take precedence for execution comparisons. Buy-and-hold in a platform summary starts before the strategy’s startup; the separately recorded startup-matched passive controls are the relevant aligned comparison.

The weight chart is a mathematical illustration using alpha = 2/21. Its finite display omits ages 60 and older; the remaining EMA weight is about 0.247%. The equal-average-age statement follows from the geometric weight formula and describes an established linear trend, rather than an assertion about every observed reversal.

TrainBard completed study batch with verified market, dates, cost and combination count.

Original TrainBard completion for 12,152 EMA/SMA settings on the later BTCUSDT four-hour frame. This is one component of the full study, with dates, cost and grid visible.