Exponential Moving Average
Exponential moving average of the chosen price, weighting recent bars more, drawn on the candles.
- EMA
- Built into Spectral
- Updates every tick
- ema
- moving average
- trend
- exponential
MIT-0: free to use, change and share, no attribution needed. What you build from it is yours.
Already in Spectral: add it from the Indicators toolbox. The file here is the same indicator written as a custom indicator, to change or learn from. Installed, it appears next to the built-in one, marked Custom.

Overview
The exponential moving average weights each new price by 2 / (Length + 1) and carries the rest of its previous value forward. Recent bars therefore count more than older ones, and the line reacts faster than a simple average of the same length.
How to read it
A rising EMA describes positive recent price pressure; a falling EMA describes negative pressure. Traders watch how price behaves around the line (holds, reclaims, rejections) and how several EMAs are stacked, rather than treating a single cross as a signal.
An EMA reacts sooner than an SMA of the same length but also turns more often in choppy markets.
Settings and limitations
Length defaults to 21 bars; the presets add 8, 13, 48, 50 and 200. The line starts at the first bar without a warm-up, so its earliest values lean heavily on the first prices and settle after a few multiples of Length.
Notes
Computes the same values as the built-in EMA in Spectral. The built-in lists one toolbox entry per length; this file covers them with one indicator and its presets.
Settings
Each setting appears in the indicator's settings panel in Spectral, next to a color setting for every output.
| Setting | Type | Default | Range or options | What it does |
|---|---|---|---|---|
| Length | Whole number | 21 | 1 – 1000 | Smoothing length in bars. Shorter lengths follow price closely; longer lengths smooth more. |
| Source | Price source | close | open, high, low, close, hlc3 | Price the average is calculated from. |
Presets
Each preset is its own entry in the Indicators toolbox, with these settings changed.
| Toolbox entry | Short name | Settings |
|---|---|---|
| EMA 8 | EMA 8 | Length: 8 |
| EMA 13 | EMA 13 | Length: 13 |
| EMA 48 | EMA 48 | Length: 48 |
| EMA 50 | EMA 50 | Length: 50 |
| EMA 200 | EMA 200 | Length: 200 |
What it draws
Lines
- EMAsolid · 1 px · primary
#8AA9C3
Source
Save it as ema.js and add it with Indicators → Custom indicators → Add file…. The format is explained in the custom indicators guide.
// Copyright (c) 2026 Spectral
// SPDX-License-Identifier: MIT-0
// Free to use, copy, modify and share: https://spectral.trade/docs/custom-indicators/LICENSE.txt
/** @type {import('./spectral-indicator').IndicatorV1} */
export default {
schemaVersion: 1,
id: 'ema',
name: 'Exponential Moving Average',
shortName: 'EMA',
version: '1.0.0',
author: 'Spectral',
description: 'Exponential moving average of the chosen price, weighting recent bars more, drawn on the candles.',
pane: 'price',
live: { lookback: 0 },
inputs: {
length: { type: 'integer', label: 'Length', default: 21, min: 1, max: 1000, description: 'Smoothing length in bars. Shorter lengths follow price closely; longer lengths smooth more.' },
source: { type: 'source', label: 'Source', default: 'close', description: 'Price the average is calculated from.' },
},
plots: {
ema: { label: 'EMA', color: '#8AA9C3', lineWidth: 1, primary: true },
},
presets: [
{ id: 'ema-8', name: 'EMA 8', shortName: 'EMA 8', inputs: { length: 8 } },
{ id: 'ema-13', name: 'EMA 13', shortName: 'EMA 13', inputs: { length: 13 } },
{ id: 'ema-48', name: 'EMA 48', shortName: 'EMA 48', inputs: { length: 48 } },
{ id: 'ema-50', name: 'EMA 50', shortName: 'EMA 50', inputs: { length: 50 } },
{ id: 'ema-200', name: 'EMA 200', shortName: 'EMA 200', inputs: { length: 200 } },
],
docs: {
overview: 'The exponential moving average weights each new price by 2 / (Length + 1) and carries the rest of its previous value forward. Recent bars therefore count more than older ones, and the line reacts faster than a simple average of the same length.',
howToRead: 'A rising EMA describes positive recent price pressure; a falling EMA describes negative pressure. Traders watch how price behaves around the line (holds, reclaims, rejections) and how several EMAs are stacked, rather than treating a single cross as a signal.\n\nAn EMA reacts sooner than an SMA of the same length but also turns more often in choppy markets.',
settings: 'Length defaults to 21 bars; the presets add 8, 13, 48, 50 and 200. The line starts at the first bar without a warm-up, so its earliest values lean heavily on the first prices and settle after a few multiples of Length.',
notes: 'Computes the same values as the built-in EMA in Spectral. The built-in lists one toolbox entry per length; this file covers them with one indicator and its presets.',
},
calculate(ctx) {
const { bars, inputs, ta } = ctx;
return { plots: { ema: ta.ema(ta.source(bars, inputs.source), inputs.length) } };
},
};Adapt it with an LLM
Paste this into your assistant and replace the second-to-last line with the change you want.
Start from this Spectral custom indicator: https://spectral.trade/indicators/ema.js Format reference: https://spectral.trade/docs/custom-indicators.llm.md Keep the file format and every rule of the reference; give the result a new id, name, shortName and version, and update docs and input descriptions to match. Keep its live updates exact and fast (section "Fast live updates" of the reference): carry values from bar to bar only through ctx.ta, and raise live.lookback if the change reads further back; Spectral rejects a file whose live updates differ from a full recalculation or are too slow. Change I want: <describe the change> Answer with the complete file in one code block, ready to save as <id>.js.


