Triple Exponential Moving Average (TEMA)
Created by Patrick G. Mulloy, the Triple exponential moving average is a faster multi-smoothed EMA of the price over a lookback window. [Discuss] 💬
// C# usage syntax
IReadOnlyList<TemaResult> results =
bars.ToTema(lookbackPeriods);Create a buffer list and add each bar as it arrives:
TemaList temaList = new(lookbackPeriods);
// call from your WebSocket or SSE message handler
void OnBarReceived(IBar bar) => temaList.Add(bar);
// the list itself holds the results; fills as the handler runs
IReadOnlyList<TemaResult> results = temaList;See Buffer lists for the full usage guide.
Subscribe to a BarHub and add each bar as it arrives:
BarHub barHub = new();
TemaHub observer = barHub.ToTemaHub(lookbackPeriods);
// call from your WebSocket or SSE message handler
void OnBarReceived(IBar bar) => barHub.Add(bar);
// results fill as the handler runs
IReadOnlyList<TemaResult> results = observer.Results;See Stream hubs for the full usage guide.
Parameters
| param | description |
|---|---|
lookbackPeriodsint | Number of periods (N) in the moving average. Must be greater than 0. Default is 20. |
Historical price bars requirements
You must have at least N periods of bars to produce any TEMA values. However, due to the nature of the smoothing technique, we recommend you use at least 3×N+250 data points prior to the intended usage date for better precision. See warmup and convergence guidance for more information.
bars is a collection of generic TBar historical price bars. It should have a consistent frequency (day, hour, minute, etc). See the Guide for more information.
Response
IReadOnlyList<TemaResult>- This method returns a time series of all available indicator values for the
barsprovided. - It always returns the same number of elements as there are in the historical price bars.
- It does not return a single incremental indicator value.
- The first
N-1periods will havenullvalues since there's not enough data to calculate. Also note that we are using the proper weighted variant for TEMA. If you prefer the unweighted raw 3 EMAs value, please use theEma3output from the TRIX oscillator instead.
TemaList : IReadOnlyList<TemaResult>- The list itself holds the results, one for each bar or value added, in timestamp order.
- It keeps up to 100,000 results by default and drops the oldest beyond that; set
MaxListSizeto keep fewer. - The first
N-1periods will havenullvalues since there's not enough data to calculate. Also note that we are using the proper weighted variant for TEMA. If you prefer the unweighted raw 3 EMAs value, please use theEma3output from the TRIX oscillator instead.
IReadOnlyList<TemaResult> results = observer.Results;observer.Resultsholds the results, one for each bar in theBarHubcache, in timestamp order.- Results update as bars arrive, including bars that arrive late or are revised.
- The cache keeps up to 100,000 results by default; set
maxCacheSizeon theBarHubto keep fewer. - The first
N-1periods will havenullvalues since there's not enough data to calculate. Also note that we are using the proper weighted variant for TEMA. If you prefer the unweighted raw 3 EMAs value, please use theEma3output from the TRIX oscillator instead.
Example for TEMA(20):
Period 1-19: null values (incalculable)
Period 20: first TEMA value (may have convergence issues)
Period 160+: fully converged, reliable valuesⓘ Incalculable periods: The first
N-1periods will havenullvalues since there's not enough data to calculate.
🚩 ⚞ Convergence warning
The first 3×N+100 periods will have decreasing magnitude, convergence-related precision errors that can be as high as ~5% deviation in indicator values for earlier periods. Use the .RemoveWarmupPeriods() method to remove these potentially unreliable values.
TemaResult
| property | description |
|---|---|
TimestampDateTime | Date from evaluated TBar |
Temadouble? | Triple exponential moving average |
Chaining
This indicator may be generated from any chain-enabled indicator or method.
// example
var results = bars
.Use(CandlePart.HL2)
.ToTema(..);Results can be further processed on Tema with additional chain-enabled indicators.
// example
var results = bars
.ToTema(..)
.ToRsi(..);See Chaining indicators for more.
This indicator may be generated from results of another chain-enabled buffer list. Add each new result to it yourself.
// example
SmaList smaList = new(..);
TemaList temaList = new(..);
void OnBarReceived(IBar bar)
{
smaList.Add(bar);
temaList.Add(smaList[^1]);
}Add each new result to another chain-enabled buffer list to process Tema further.
// example
TemaList temaList = new(..);
RsiList rsiList = new(..);
void OnBarReceived(IBar bar)
{
temaList.Add(bar);
rsiList.Add(temaList[^1]);
}See Chaining buffer lists for more.
This indicator may be subscribed to any chain-enabled hub.
// example
TemaHub observer = barHub
.ToBarPartHub(CandlePart.HL2)
.ToTemaHub(..);Subscribe other chain-enabled hubs to it to process Tema further.
// example
RsiHub observer = barHub
.ToTemaHub(..)
.ToRsiHub(..);See Chaining stream hubs for more.
Utilities
Call these on the list itself, as in temaList.Find(lookupDate). .Condense() returns a new list and leaves temaList unchanged.
Warmup removal is left out. Once the list is full it drops its oldest results, so trimming by position would remove valid values.
Call these on observer.Results, as in observer.Results.Find(lookupDate). .Condense() returns a new list and leaves the hub's results unchanged.
Warmup removal is left out. Once the cache is full the hub drops its oldest results, so trimming by position would remove valid values.
See Utilities and helpers for more information.