Moving AveragesPine Script v6

ta.ema()Exponential Moving Average

Computes the exponential moving average (EMA) of the source with smoothing constant alpha = 2 / (length + 1). Recent values have more influence than older ones, giving greater weight to the latest observations than an equal-weight SMA window. Responsiveness depends on the price path.

TradingView language reference

Syntax

Syntax
ta.ema(source, length) → series float

Arguments

ParameterTypeDescription
sourceseries int/floatSeries of values to process.
lengthsimple intEMA length; defines alpha = 2 / (length + 1).

Returns

Exponential moving average of source with alpha = 2 / (length + 1).

Remarks

The built-in ignores na source values. The hand-written recurrence below illustrates the formula on a continuous price series; it does not reproduce all built-in missing-value handling. An open-bar source can change, and requested data may have separate confirmation rules.

Code Examples

Pine Script v6 Example
//@version=6
indicator("ta.ema")
plot(ta.ema(close, 15))

//the same on pine
pine_ema(src, length) =>
    alpha = 2 / (length + 1)
    sum = 0.0
    sum := na(sum[1]) ? src : alpha * src + (1 - alpha) * nz(sum[1])
plot(pine_ema(close,15))

Trading Applications

React faster to recent price changes than SMA

Build MACD-like custom indicators

Create responsive trend-following systems

Combine with other indicators for confluence signals

Frequently Asked Questions

ta.ema() returns the exponential moving average of a source series. Each new value blends the current source with the previous EMA using a fixed alpha derived from length, which differs from averaging a fixed window with equal weights.

SMA averages a fixed window with equal weights. EMA applies recursive exponential smoothing so older data fades gradually. For the same nominal length, EMA typically turns sooner and hugs price more closely.

TradingView documents that using this function can contribute to repainting in some setups—often when the calculation depends on data that is not fixed on a closed bar (e.g., unconfirmed realtime values or lookahead). A closed chart bar alone does not confirm a requested higher-timeframe input; changed data, history or settings can also alter recalculated values.

Generate ta.ema() Code with AI

Draft Pine Script using ta.ema() with Pineify's AI Coding Agent, then review the arguments and test the result on your chart. Usage depends on your plan and available credits.