Skip to content

An exponential moving average with a band drawn a fixed percentage either side.

How far the price has strayed from its exponential moving average, against a fixed percentage band. It turns sooner than the SMA Envelope because the EMA does.

Read it like the SMA Envelope: closes outside the band are stretched from the average. Choose the width for the market and timeframe.

middle = EMA(periods)
lower = middle − middle × envelope / 100
upper = middle + middle × envelope / 100

Call: emaEnvelope(periods, envelope)

Setting Chart default
periods: Periods 20
envelope: Envelope (%) none

What you get: a list of 3, in this order: 1. a number; 2. a number; 3. a number.

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

EMA Envelope 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 band = emaEnvelope(20, 0.2);
log("Distance to upper band in pips", (band[1] - CLOSE) / PIP_SIZE);
}

envelope has no default: give it in every call. It must be above 0 and below 100.