122 lines
3.5 KiB
Markdown
122 lines
3.5 KiB
Markdown
---
|
|
title: tripleEMA() function
|
|
description: >
|
|
`tripleEMA()` returns the triple exponential moving average (TEMA) of values in
|
|
the `_value` column.
|
|
menu:
|
|
flux_v0_ref:
|
|
name: tripleEMA
|
|
parent: universe
|
|
identifier: universe/tripleEMA
|
|
weight: 101
|
|
flux/v0/tags: [transformations]
|
|
introduced: 0.38.0
|
|
---
|
|
|
|
<!------------------------------------------------------------------------------
|
|
|
|
IMPORTANT: This page was generated from comments in the Flux source code. Any
|
|
edits made directly to this page will be overwritten the next time the
|
|
documentation is generated.
|
|
|
|
To make updates to this documentation, update the function comments above the
|
|
function definition in the Flux source code:
|
|
|
|
https://github.com/influxdata/flux/blob/master/stdlib/universe/universe.flux#L4541-L4549
|
|
|
|
Contributing to Flux: https://github.com/influxdata/flux#contributing
|
|
Fluxdoc syntax: https://github.com/influxdata/flux/blob/master/docs/fluxdoc.md
|
|
|
|
------------------------------------------------------------------------------->
|
|
|
|
`tripleEMA()` returns the triple exponential moving average (TEMA) of values in
|
|
the `_value` column.
|
|
|
|
`tripleEMA` uses `n` number of points to calculate the TEMA, giving more
|
|
weight to recent data with less lag than `exponentialMovingAverage()` and
|
|
`doubleEMA()`.
|
|
|
|
#### Triple exponential moving average rules
|
|
- A triple exponential moving average is defined as `tripleEMA = (3 * EMA_1) - (3 * EMA_2) + EMA_3`.
|
|
- `EMA_1` is the exponential moving average of the original data.
|
|
- `EMA_2` is the exponential moving average of `EMA_1`.
|
|
- `EMA_3` is the exponential moving average of `EMA_2`.
|
|
- A true triple exponential moving average requires at least requires at least
|
|
`3 * n - 2` values. If not enough values exist to calculate the TEMA, it
|
|
returns a `NaN` value.
|
|
- `tripleEMA()` inherits all `exponentialMovingAverage()` rules.
|
|
|
|
##### Function type signature
|
|
|
|
```js
|
|
(<-tables: stream[{A with _value: B}], n: int) => stream[C] where B: Numeric, C: Record
|
|
```
|
|
|
|
{{% caption %}}
|
|
For more information, see [Function type signatures](/flux/v0/function-type-signatures/).
|
|
{{% /caption %}}
|
|
|
|
## Parameters
|
|
|
|
### n
|
|
({{< req >}})
|
|
Number of points to use in the calculation.
|
|
|
|
|
|
|
|
### tables
|
|
|
|
Input data. Default is piped-forward data (`<-`).
|
|
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
### Calculate a three point triple exponential moving average
|
|
|
|
```js
|
|
import "sampledata"
|
|
|
|
sampledata.int()
|
|
|> tripleEMA(n: 3)
|
|
|
|
```
|
|
|
|
{{< expand-wrapper >}}
|
|
{{% expand "View example input and output" %}}
|
|
|
|
#### Input data
|
|
|
|
| _time | _value | *tag |
|
|
| -------------------- | ------- | ---- |
|
|
| 2021-01-01T00:00:00Z | -2 | t1 |
|
|
| 2021-01-01T00:00:10Z | 10 | t1 |
|
|
| 2021-01-01T00:00:20Z | 7 | t1 |
|
|
| 2021-01-01T00:00:30Z | 17 | t1 |
|
|
| 2021-01-01T00:00:40Z | 15 | t1 |
|
|
| 2021-01-01T00:00:50Z | 4 | t1 |
|
|
|
|
| _time | _value | *tag |
|
|
| -------------------- | ------- | ---- |
|
|
| 2021-01-01T00:00:00Z | 19 | t2 |
|
|
| 2021-01-01T00:00:10Z | 4 | t2 |
|
|
| 2021-01-01T00:00:20Z | -3 | t2 |
|
|
| 2021-01-01T00:00:30Z | 19 | t2 |
|
|
| 2021-01-01T00:00:40Z | 13 | t2 |
|
|
| 2021-01-01T00:00:50Z | 1 | t2 |
|
|
|
|
|
|
#### Output data
|
|
|
|
| _time | _value | *tag |
|
|
| -------------------- | ------------------ | ---- |
|
|
| 2021-01-01T00:00:50Z | 7.6250000000000036 | t1 |
|
|
|
|
| _time | _value | *tag |
|
|
| -------------------- | ------------------ | ---- |
|
|
| 2021-01-01T00:00:50Z | 4.0729166666666625 | t2 |
|
|
|
|
{{% /expand %}}
|
|
{{< /expand-wrapper >}}
|