ta.ema#
Exponential moving average over values ending at index i.
SYNTAX#
function ta.ema(values: (number | null)[], length: number, i: number): number | nullARGUMENTS#
values((number | null)[]) — Series of input values, oldest-first.length(number) — Smoothing period. Must be positive.i(number) — Current bar index.
RETURNS#
number | null — EMA value, or null during warmup or on missing data.
REMARKS#
First valid output is at i = length - 1 (matches ta.sma for that bar). Any null/NaN value in the warmup window propagates; subsequent bars also propagate null on missing inputs.
EXAMPLE#
const closes = [];
function onBar(i, ctx) {
closes[i] = candles[i].close;
const ema20 = ta.ema(closes, 20, i);
const ema50 = ta.ema(closes, 50, i);
if (ema20 !== null) plot('ema20', ema20, { color: '#26a69a' });
if (ema50 !== null) plot('ema50', ema50, { color: '#ef5350' });
}