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, giving greater weight to the latest observations than an equal-weight SMA window. Responsiveness depends on the price path.
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
The built-in ignores na source values. The hand-written recurrence below illustrates the formula on a continuous price series; it does not reproduce all built-in missing-value handling. An open-bar source can change, and requested data may have separate confirmation rules.
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
Draft Pine Script using ta.ema() with Pineify's AI Coding Agent, then review the arguments and test the result on your chart. Usage depends on your plan and available credits.
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() - Wilder 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.