docs-v2/content/v2.0/reference/flux/stdlib/built-in/transformations/tripleema.md

2.7 KiB

title description aliases menu weight related
tripleEMA() function The `tripleEMA()` function calculates the exponential moving average of values grouped into `n` number of points, giving more weight to recent data with less lag than `exponentialMovingAverage()` and `doubleEMA()`.
/v2.0/reference/flux/functions/built-in/transformations/aggregates/tripleema/
/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/tripleema/
v2_0_ref
name parent
tripleEMA built-in-transformations
402
/v2.0/reference/flux/stdlib/built-in/transformations/movingaverage/
/v2.0/reference/flux/stdlib/built-in/transformations/doubleema/
/v2.0/reference/flux/stdlib/built-in/transformations/timedmovingaverage/
/v2.0/reference/flux/stdlib/built-in/transformations/exponentialmovingaverage/
https://docs.influxdata.com/influxdb/latest/query_language/functions/#triple-exponential-moving-average, InfluxQL TRIPLE_EXPONENTIAL_MOVING_AVERAGE()

The tripleEMA() function calculates the exponential moving average of values in the _value column grouped into n number of points, giving more weight to recent data with less lag than exponentialMovingAverage() and doubleEMA().

Function type: Transformation

tripleEMA(n: 5)
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 triple EMA, it returns a NaN value.
  • tripleEMA() inherits all exponential moving average rules.

Parameters

n

The number of points to average.

Data type: Integer

Examples

Calculate a five point triple exponential moving average

from(bucket: "example-bucket"):
  |> range(start: -12h)
  |> tripleEMA(n: 5)

Function definition

tripleEMA = (n, tables=<-) =>
	tables
		|> exponentialMovingAverage(n:n)
		|> duplicate(column:"_value", as:"ema1")
    |> exponentialMovingAverage(n:n)
		|> duplicate(column:"_value", as:"ema2")
		|> exponentialMovingAverage(n:n)
		|> map(fn: (r) => ({r with _value: 3.0 * r.ema1 - 3.0 * r.ema2 + r._value}))
		|> drop(columns: ["ema1", "ema2"])