---
title: doubleEMA() function
description: doubleEMA() returns the double exponential moving average (DEMA) of values in the _value column grouped into n number of points, giving more weight to recent data.
url: https://docs.influxdata.com/flux/v0/stdlib/universe/doubleema/
estimated_tokens: 914
product: Flux
version: v0
publisher: InfluxData
canonical: https://docs.influxdata.com/flux/v0/stdlib/universe/doubleema/
date: '2024-04-08T16:01:02-06:00'
lastmod: '2024-04-08T16:01:02-06:00'
---

* Flux 0.38.0+

InfluxDB support

`doubleEMA()` returns the double exponential moving average (DEMA) of values in
the `_value` column grouped into `n` number of points, giving more weight to
recent data.

#### Double exponential moving average rules

* A double exponential moving average is defined as `doubleEMA = 2 * EMA_N - EMA of EMA_N`.
  * `EMA` is an exponential moving average.
  * `N = n` is the period used to calculate the `EMA`.

* A true double exponential moving average requires at least `2 * n - 1` values.
  If not enough values exist to calculate the double `EMA`, it returns a `NaN` value.
* `doubleEMA()` inherits all `exponentialMovingAverage()` rules.

##### Function type signature

```js
(<-tables: stream[{A with _value: B}], n: int) => stream[C] where B: Numeric, C: Record
```

For more information, see [Function type signatures](/flux/v0/function-type-signatures/).

## Parameters

### n

(Required)
Number of points to average.

### tables

Input data. Default is piped-forward data (`<-`).

## Examples

### Calculate a three point double exponential moving average

```js
import "sampledata"

sampledata.int()
    |> doubleEMA(n: 3)
```

[](#view-example-input-and-output)

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:40Z|16.333333333333336| t1  |
|2021-01-01T00:00:50Z|7.916666666666668 | t1  |

|       \_time       |     \_value      |\*tag|
|--------------------|------------------|-----|
|2021-01-01T00:00:40Z|15.027777777777779| t2  |
|2021-01-01T00:00:50Z|5.034722222222221 | t2  |

#### Related

* [movingAverage() function](/flux/v0/stdlib/universe/movingaverage/)
* [tripleEMA() function](/flux/v0/stdlib/universe/tripleema/)
* [timedMovingAverage() function](/flux/v0/stdlib/universe/timedmovingaverage/)
* [exponentialMovingAverage() function](/flux/v0/stdlib/universe/exponentialmovingaverage/)
* [InfluxQL DOUBLE\_EXPONENTIAL\_MOVING\_AVERAGE()](/influxdb/v1/query_language/functions/#double-exponential-moving-average)

[transformations](/flux/v0/tags/transformations/)
| _time | _value | *tag |
| --- | --- | --- |
| _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 |
| --- | --- | --- |
| _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 |

| _time | _value | *tag |
| --- | --- | --- |
| _time | _value | *tag |
| 2021-01-01T00:00:40Z | 16.333333333333336 | t1 |
| 2021-01-01T00:00:50Z | 7.916666666666668 | t1 |

| _time | _value | *tag |
| --- | --- | --- |
| _time | _value | *tag |
| 2021-01-01T00:00:40Z | 15.027777777777779 | t2 |
| 2021-01-01T00:00:50Z | 5.034722222222221 | t2 |
