tripleEMA() function

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*

  1. 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

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

Function definition

  1. tripleEMA = (n, tables=<-) =>
  2. tables
  3. |> exponentialMovingAverage(n:n)
  4. |> duplicate(column:"_value", as:"ema1")
  5. |> exponentialMovingAverage(n:n)
  6. |> duplicate(column:"_value", as:"ema2")
  7. |> exponentialMovingAverage(n:n)
  8. |> map(fn: (r) => ({r with _value: 3.0 * r.ema1 - 3.0 * r.ema2 + r._value}))
  9. |> drop(columns: ["ema1", "ema2"])

Related articles