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, so the EMA follows price more quickly than an SMA of the same length.

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

Please note that using this variable/function can cause indicator repainting. na values in the source series are ignored.

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, so the line is more responsive than a simple average.

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). On historical bars, the EMA values are stable once the bar is closed.

Generate ta.ema() Code with AI

Skip the manual coding. Use Pineify's AI Coding Agent to generate Pine Script code using ta.ema() and other built-in functions instantly.