TradingView indicators

Exponential moving average on TradingView

The exponential moving average indicator (EMA) smooths a price series by giving recent observations more weight. Its length sets how quickly those weights decay. A 20 EMA assigns about 9.52% to the latest value and 90.48% to the previous EMA, so its history extends beyond the last 20 bars.

EMA = α × source + (1 − α) × previous EMA
α = 2 / (length + 1)

The source, timeframe and initial value matter as well as the length.

View the Pine Script example

How the weights decay

Each new bar multiplies the contribution of an older observation by (1 − α). After k further updates, an observation introduced through the recurrence has weight α × (1 − α)k. With length 20, the current observation has 9.52% weight, the previous one 8.62%, and the observation 19 bars ago about 1.42%. Older observations still contribute through the previous EMA.

This differs from an SMA, which removes an observation when it leaves the fixed window. The EMA formula and input controls are described in TradingView's EMA documentation.

One hypothetical update

Suppose the previous 20 EMA is 100 and the new close is 110. The new value is (2/21 × 110) + (19/21 × 100) = 100.9524. A second close of 110 produces 101.8141. These are illustrative inputs, not historical prices or trading results.

Initialization: the first EMA still matters later

A recursive formula needs a starting value. Seeding with a first price and seeding with an initial average are different conventions. When comparing a spreadsheet or another platform with TradingView, match the initialization rule and available history as well as the formula. Use Pine's built-in EMA for the TradingView example below instead of assuming that a custom seed reproduces it.

The arithmetic gives a useful diagnostic: if two calculations start D units apart and receive identical subsequent values, their difference after m updates is D × (1 − α)m. For a 20 EMA, a hypothetical initial difference of 1 becomes about 0.1351 after 20 updates and 0.00247 after 60. A longer history reduces that difference; there is no universal warm-up length that makes every comparison exact.

TradingView specifically lists EMA among the functions whose results can depend on early history. Compare values well after the first available bars and record the tolerance acceptable for your calculation.

Same length, different source

Close, hl2 and hlc3 supply different observations to the same recurrence. With a hypothetical high of 110, low of 90 and close of 108, close is 108, hl2 is 100 and hlc3 is about 102.67. Starting all three 20 EMAs at 100 produces 100.762, 100.000 and 100.254 respectively after this update. The formula is unchanged; the inputs explain the difference.

Pine's chart information documentation defines hl2 as (high + low)/2 and hlc3 as (high + low + close)/3. Neither is inherently the correct source for every task.

Check these inputs before diagnosing an EMA mismatch
SettingWhat to compare
Symbol and feedExact exchange, instrument and available historical bars.
Timeframe and sessionChart interval, indicator interval and whether extended-hours bars are included.
Source and adjustmentsClose or another price series; adjusted and unadjusted data must match.
Chart typeStandard candles or synthetic OHLC values such as Heikin Ashi.
Display and extra smoothingUse offset zero and compare the EMA itself, not an additional smoothing line.

An EMA on Heikin Ashi close averages synthetic values. TradingView explains how those prices differ from market prices. Changing only the length cannot reconcile those two input series.

EMA versus SMA: response and noise at the same length

Under identical inputs, a 20 EMA responds more strongly to the newest observation than a 20 SMA: 9.52% versus 5%. That also gives a one-bar disturbance more immediate influence. Faster response by itself says nothing about whether the disturbance will persist.

For an illustrative step from a long, constant history of 100 to repeated values of 110, both averages start at 100. After one new bar, EMA is 100.9524 and SMA is 100.5. After 20 new bars, EMA is approximately 108.6489 while SMA is 110 because its old window has fully rolled out. EMA reacts more initially but retains a decaying tail. It does not reach every new level before the SMA.

Shortening the EMA length increases α and sensitivity to each new observation. Lengthening it reduces that sensitivity but also slows the response to a sustained change. Compare the same symbol, source and timeframe before attributing a difference to the averaging method. A smooth line is not evidence of a profitable rule.

A Pine Script v6 EMA example

Paste this indicator into TradingView's Pine Editor and add it to the chart. It plots one EMA using the chart's data, with a selectable source and length. The example starts at 20; change the input to match the indicator you are comparing.

Pine Script v6
//@version=6
indicator("Exponential Moving Average", overlay=true)

length = input.int(20, "Length", minval=1)
source = input.source(close, "Source")
emaValue = ta.ema(source, length)

plot(emaValue, "EMA", color=color.blue, linewidth=2)

On an open bar, close is the latest price, so this EMA can change until that bar closes. Use closed bars for a reproducible comparison. This example uses no higher-timeframe requests, order logic or crossover alerts. For those rules, continue to the EMA crossover strategy guide.

To reconcile values, set the comparison indicator to the same length, source and timeframe, remove any plot offset, and inspect the same closed bar. Start with the ta.ema function reference if you need its API details.

Build an EMA filter with Pineify

Pineify's AI Coding Agent can draft a script from your EMA and price-filter requirements. Specify the source, length, chart timeframe and whether the filter is evaluated at bar close. Review the generated code and compare its output in TradingView. The Visual Editor also provides EMA source and length inputs for a configured workflow.

EMA questions

What does moving average exponential mean?

It means an exponential moving average, or EMA: a recursive average whose weights decrease geometrically with age. For length N, the usual smoothing factor is 2/(N+1). The length controls the decay rate; it does not remove every observation older than N bars.

How much weight does a 20-period EMA give the latest price?

A 20-period EMA gives the latest source value 2/21, about 9.52%, of the new EMA value. The other 90.48% comes from the previous EMA, which already contains older observations. A 20-period SMA gives each of its 20 observations 5%.

Why do two EMAs with the same length show different values?

The inputs or calculation context may differ. Check the exact symbol and feed, timeframe, source, session, price adjustments, chart type and plot offset. If these match, compare historical coverage and initialization. A different initial value can affect later EMA values even when subsequent prices match.

Does the exponential moving average indicator repaint?

An EMA based on close changes while the current bar is open because close is the latest traded price until that bar closes. Comparing confirmed bars removes that particular intrabar difference. Historical data revisions or a change in available starting history can still change previously calculated values.

Is a 20 EMA on a four-hour chart the same as a daily EMA?

No. Length counts bars in the calculation timeframe. A 20 EMA on a four-hour chart processes four-hour observations, while a daily EMA processes daily observations. Changing the timeframe changes both the inputs and the times at which the recursive average is updated.

Is there one best EMA length?

No length is best for every purpose. A shorter length increases the weight of the newest observation; a longer length reduces it. The example uses 20 to make the arithmetic easy to compare. That is an example setting, not a recommendation or a claim about returns.

Sources and related reading

Official documentation checked on October 16, 2026. Numerical examples are hypothetical calculations.

Browse the TradingView indicator collection or compare the RMA smoothing method.

Educational information, not investment advice. An EMA summarizes its input history; it does not predict prices or guarantee trading results. The examples here do not measure strategy performance.