All indicators
Trend / Price pane

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

By Spectral · v1.0.0

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.

Exponential Moving Average on a Spectral chart
Spectral chart with sample market data, default settings.

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.

SettingTypeDefaultRange or optionsWhat it does
LengthWhole number211 – 1000Smoothing length in bars. Shorter lengths follow price closely; longer lengths smooth more.
SourcePrice sourcecloseopen, high, low, close, hlc3Price the average is calculated from.

Presets

Each preset is its own entry in the Indicators toolbox, with these settings changed.

Toolbox entryShort nameSettings
EMA 8EMA 8Length: 8
EMA 13EMA 13Length: 13
EMA 48EMA 48Length: 48
EMA 50EMA 50Length: 50
EMA 200EMA 200Length: 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.