ta.ema() - Pine Script Function
ta.ema()
Section titled “ta.ema()”Overview
Section titled “Overview”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).
Syntax
Section titled “Syntax”ta.ema(source, length) → series floatParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| source | series int/float | Series of values to process. |
Returns
Section titled “Returns”Exponential moving average of source with alpha = 2 / (length + 1).
Remarks
Section titled “Remarks”- Please note that using this variable/function can cause indicator repainting.
Examples
Section titled “Examples”Example 1
Section titled “Example 1”//@version=6indicator("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))