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

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.