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
ta.ema(source, length) → series floatArguments
| Parameter | Type | Description |
|---|---|---|
| source | series int/float | Series of values to process. |
| length | simple int | EMA 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
//@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.
Related Pine Script Functions
ta.sma() - Simple Moving Average
Learn how to use ta.sma() in Pine Script. Syntax, parameters, code examples, and trading applications for the Simple Moving Average function.
ta.wma() - Weighted Moving Average
Learn how to use ta.wma() in Pine Script. Syntax, parameters, code examples, and trading applications for the Weighted Moving Average function.
ta.rma() - Relative Moving Average
Learn how to use ta.rma() in Pine Script. Syntax, parameters, code examples for Wilder's smoothing method used in RSI calculation.
ta.hma() - Hull Moving Average
Learn how to use ta.hma() in Pine Script. Syntax, parameters, code examples for the fast, low-lag Hull Moving Average.
ta.alma() - Arnaud Legoux Moving Average
Learn how to use ta.alma() in Pine Script. Syntax, parameters including offset and sigma, code examples for ALMA.