Triple Exponential Moving Average
Patrick Mulloy's triple exponential moving average: an EMA with its lag corrected twice, drawn on the candles.
- TEMA
- Built into Spectral
- Updates every tick
- tema
- triple ema
- moving average
- low lag
- trend
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 Triple Exponential Moving Average, published by Patrick Mulloy in 1994, removes the lag of an exponential average more thoroughly than the DEMA. It stacks three EMAs (an EMA of price, an EMA of that, and an EMA of the second) and plots three times the first, minus three times the second, plus the third.
The combination cancels most of the delay an EMA carries, so the line hugs price closely while still filtering some of the bar-to-bar noise.
How to read it
TEMA is the fastest of the classic exponential averages: its slope shows the short-term direction almost as soon as price turns, and it suits traders who want a trend line that stays close to price. Crosses with a slower average come early.
The price of that speed is noise: it overshoots after sharp moves and changes direction often in sideways markets, so it is better read together with a slower average or with price structure than on its own.
Settings and limitations
Length defaults to 9 bars, as on TradingView; the presets add 21, 50 and 200. All three inner averages use the same length.
The line starts at the first bar with no warm-up, so its earliest values lean on the first prices and settle after a few multiples of Length.
Notes
Computes 3 x EMA1 - 3 x EMA2 + EMA3, Mulloy's formula. Each EMA starts from its first value, like Spectral's EMA; platforms that start an EMA from a simple average, TradingView among them, draw nothing for the first 3 x Length - 3 bars, and the values agree once warmed up. It is not TRIX, the oscillator built from the rate of change of a triple-smoothed EMA.
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 | 9 | 1 – 1000 | Length of the three exponential averages inside the TEMA. Longer lengths are smoother and react later. |
| 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 |
|---|---|---|
| TEMA 21 | TEMA 21 | Length: 21 |
| TEMA 50 | TEMA 50 | Length: 50 |
| TEMA 200 | TEMA 200 | Length: 200 |
What it draws
Lines
- TEMAsolid · 1 px · primary
#C98FA8
Source
Save it as tema.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').IndicatorV2} */
export default {
schemaVersion: 2,
id: 'tema',
name: 'Triple Exponential Moving Average',
shortName: 'TEMA',
version: '1.0.0',
author: 'Spectral',
description: 'Patrick Mulloy\'s triple exponential moving average: an EMA with its lag corrected twice, drawn on the candles.',
pane: 'price',
live: { lookback: 0 },
inputs: {
length: { type: 'integer', label: 'Length', default: 9, min: 1, max: 1000, description: 'Length of the three exponential averages inside the TEMA. Longer lengths are smoother and react later.' },
source: { type: 'source', label: 'Source', default: 'close', description: 'Price the average is calculated from.' },
},
plots: {
tema: { label: 'TEMA', color: '#C98FA8', lineWidth: 1, primary: true },
},
presets: [
{ id: 'tema-21', name: 'TEMA 21', shortName: 'TEMA 21', inputs: { length: 21 } },
{ id: 'tema-50', name: 'TEMA 50', shortName: 'TEMA 50', inputs: { length: 50 } },
{ id: 'tema-200', name: 'TEMA 200', shortName: 'TEMA 200', inputs: { length: 200 } },
],
docs: {
overview: 'The Triple Exponential Moving Average, published by Patrick Mulloy in 1994, removes the lag of an exponential average more thoroughly than the DEMA. It stacks three EMAs (an EMA of price, an EMA of that, and an EMA of the second) and plots three times the first, minus three times the second, plus the third.\n\nThe combination cancels most of the delay an EMA carries, so the line hugs price closely while still filtering some of the bar-to-bar noise.',
howToRead: 'TEMA is the fastest of the classic exponential averages: its slope shows the short-term direction almost as soon as price turns, and it suits traders who want a trend line that stays close to price. Crosses with a slower average come early.\n\nThe price of that speed is noise: it overshoots after sharp moves and changes direction often in sideways markets, so it is better read together with a slower average or with price structure than on its own.',
settings: 'Length defaults to 9 bars, as on TradingView; the presets add 21, 50 and 200. All three inner averages use the same length.\n\nThe line starts at the first bar with no warm-up, so its earliest values lean on the first prices and settle after a few multiples of Length.',
notes: 'Computes 3 x EMA1 - 3 x EMA2 + EMA3, Mulloy\'s formula. Each EMA starts from its first value, like Spectral\'s EMA; platforms that start an EMA from a simple average, TradingView among them, draw nothing for the first 3 x Length - 3 bars, and the values agree once warmed up. It is not TRIX, the oscillator built from the rate of change of a triple-smoothed EMA.',
},
calculate(ctx) {
const { bars, inputs, ta } = ctx;
const ema1 = ta.ema(ta.source(bars, inputs.source), inputs.length);
const ema2 = ta.ema(ema1, inputs.length);
const ema3 = ta.ema(ema2, inputs.length);
return {
plots: {
tema: ema1.map((value, index) => (value === null || ema2[index] === null || ema3[index] === null ? null : 3 * value - 3 * ema2[index] + ema3[index])),
},
};
},
};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/tema.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.


