Triple Exponential Moving Average (TEMA)
Layered Warm-Up and Signed Weights
Install and import
npm install fintech-algorithmsimport { calculateTemaComponents } from "fintech-algorithms/technical-indicators/trend-smoothing/tema";Signature
calculateTemaComponents(values, span)Triple exponential moving average: 3 × EMA − 3 × EMA(EMA) + EMA(EMA(EMA)). More lag cancellation than DEMA, and correspondingly more overshoot.
Parameters
| Name | Type | Notes |
|---|---|---|
values | (number | null)[] | Observation series in chronological order, oldest first. nulls: propagate |
span | number | Smoothing span used for all three EMA passes; the decay factor is 2 / (span + 1). min: 1 · integer: true |
Returns
{ ema1, ema2, ema3, tema }[] · length same-as-input
One record per position carrying all three intermediate EMAs alongside the result.
Warm-up
The first 3 × (span − 1) positions are null. All three passes must fill before the combination is defined.
Errors
- When span < 1 or is not an integer — throws RangeError
Complexity: time O(n),
space O(n).
Worked example
executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.
Input
[10, 13, 12, 15, 14, 18]Showing 6 of 10 elements.
3Call
calculateTemaComponents(values, span)Returns
array of 10 objects
[
{
"value": 10,
"ema1": null,
"ema2": null,
"ema3": null,
"tema": null,
"status": "warming_ema1"
},
{
"value": 13,
"ema1": null,
"ema2": null,
"ema3": null,
"tema": null,
"status": "warming_ema1"
},
{
"value": 12,
"ema1": 11.666666666666666,
"ema2": null,
"ema3": null,
"tema": null,
"status": "warming_ema2"
}
]Showing 3 of 10 elements.
Other exports
This module also exports
calculateTema, temaSteadyStateWeight. Every module additionally exports run as an alias of its
primary function, and a meta object carrying its catalog id, domain, family,
shape and article URL.
Diagrams
Calculation flow
TEMA calculation flow
flowchart LR
A["Validate ordered finite value"] --> B["Seed or update EMA1"]
B --> C{"EMA1 ready?"}
C -- "No" --> D["Emit warming EMA1"]
C -- "Yes" --> E["Feed EMA1 into EMA2"]
E --> F["Seed or update EMA2"]
F --> G{"EMA2 ready?"}
G -- "No" --> H["Emit warming EMA2"]
G -- "Yes" --> I["Feed EMA2 into EMA3"]
I --> J["Seed or update EMA3"]
J --> K{"EMA3 ready?"}
K -- "No" --> L["Emit warming EMA3"]
K -- "Yes" --> M["Calculate EMA3 + 3 × (EMA1 − EMA2)"]
M --> N["Emit ready components and TEMA"]
How it works
This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.
References
- Smoothing Data With Faster Moving Averages — Patrick G. Mulloy; *Technical Analysis of Stocks & Commodities*
- Smoothing Data With Less Lag — Patrick G. Mulloy; *Technical Analysis of Stocks & Commodities*
- TA-Lib TEMA definition and reference implementation — TA-Lib project
- TC2000 TEMA methodology — Worden / TC2000
- Local EMA and DEMA foundation — The Fintech Builder
- Evidence and design reconciliation