Skip to content

Technical indicators

Exponential Moving Average (EMA)

A moving average that reacts faster to the latest prices.

An average in which each bar counts a little less than the one after it. It starts as the simple average of the first periods closes, then each new close pulls it a fixed fraction of the way.

Read it like a simple moving average, but expect it to turn earlier and to be pulled about more by single bars. Many other indicators, such as MACD and Keltner Channels, are built from it.

α = 2 / (periods + 1)
EMA = EMA(previous bar) + α × (close − EMA(previous bar))

The first value is the simple average of the first periods closes. Because every past close still has a little weight, it runs over twice periods bars before your start date so its value has settled.

Call: ema(periods)

Setting Chart default
periods: Periods 20

What you get: a number.

Warm-up: with ema(20), it asks for 20 bars of history and a run-up of 40, and its first value came on bar 21 of the example data.

Exponential Moving Average (EMA) drawn by its own code on example prices

The prices are made up, hourly, and the same on every page, so the chart shows how the indicator behaves, not how a market behaved.

function onIntervalClose() {
const fast = ema(12);
const slow = ema(26);
log("EMA gap in pips", (fast - slow) / PIP_SIZE);
}