Skip to content
Algo Trade Analytics Docs

ta.ema() - Pine Script Function

The ema function returns the exponentially weighted moving average. In ema weighting factors decrease exponentially. It calculates by using a formula: EMA = alpha * source + (1 - alpha) * EMA[1], where alpha = 2 / (length + 1).

ta.ema(source, length) → series float
NameTypeDescription
sourceseries int/floatSeries of values to process.

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

  • Please note that using this variable/function can cause indicator repainting.
//@version=6
indicator("ta.ema")
plot(ta.ema(close, 15))//the same on pinepine_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))