From 187b95f8f0557221e266c38be8de685172ce8675 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Fri, 9 Aug 2019 16:36:40 -0600 Subject: [PATCH 1/2] added flux tripleExponentialDerivative, resolves #373 --- .../aggregates/tripleexponentialderivative.md | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 content/v2.0/reference/flux/functions/built-in/transformations/aggregates/tripleexponentialderivative.md diff --git a/content/v2.0/reference/flux/functions/built-in/transformations/aggregates/tripleexponentialderivative.md b/content/v2.0/reference/flux/functions/built-in/transformations/aggregates/tripleexponentialderivative.md new file mode 100644 index 000000000..fcc4df79e --- /dev/null +++ b/content/v2.0/reference/flux/functions/built-in/transformations/aggregates/tripleexponentialderivative.md @@ -0,0 +1,66 @@ +--- +title: tripleExponentialDerivative() function +description: > + The `tripleExponentialDerivative()` function calculates a triple exponential + derivative of input tables using `n` points. +menu: + v2_0_ref: + name: tripleExponentialDerivative + parent: built-in-aggregates +weight: 501 +v2.0/tags: [technical analysis] +related: + - /v2.0/reference/flux/functions/built-in/transformations/aggregates/movingaverage/ + - /v2.0/reference/flux/functions/built-in/transformations/aggregates/doubleema/ + - /v2.0/reference/flux/functions/built-in/transformations/aggregates/tripleema/ + - /v2.0/reference/flux/functions/built-in/transformations/aggregates/timedmovingaverage/ + - /v2.0/reference/flux/functions/built-in/transformations/aggregates/exponentialmovingaverage/ + - https://docs.influxdata.com/influxdb/v1.7/query_language/functions/#triple-exponential-derivative, InfluxQL TRIPLE_EXPONENTIAL_DERIVATIVE() +--- + +The `tripleExponentialDerivative()` function calculates a triple exponential +derivative of input tables using `n` points. + +_**Function type:** Aggregate_ + +```js +tripleExponentialDerivative(n: 5) +``` + +Triple exponential derivative, commonly referred to as “TRIX,” is a momentum indicator and oscillator. +A triple exponential derivative is a triple exponential moving average of the log of data input over the period of time. +It prevents cycles shorter than the defined period from being considered by the indicator. +With `tripleExponentialDerivative()`, the period of time is determined by the time `n` points span. + +Triple exponential derivative oscillates around a zero line. +When used as a momentum **oscillator**, a positive value indicates an overbought market +and a negative value indicates an oversold market. +When used as a momentum **indicator**, a positive value suggests momentum is +increasing and a negative value suggests momentum is decreasing. + +##### Triple exponential moving average rules +- A triple exponential derivative is defined as: + - `TRIX[i] = ((EMA3[i] / EMA3[i - 1]) - 1) * 100`: + - `EMA_3 = EMA(EMA(EMA(data)))` +- If there are not enough values to calculate a triple exponential derivative, + the output `_value` is `NaN`; all other columns are the same as the _last_ record of the input table. +- The behavior of the exponential moving averages used for calculating the triple + exponential derivative is the same as [`exponentialMovingAverage`](/v2.0/reference/flux/functions/built-in/transformations/aggregates/exponentialmovingaverage/): + - `tripleExponentialDerivative` ignores `null` values and does not inlcude them in the calculation. + - It acts only on the `_value` column. + +## Parameters + +### n +The number of points to use in the calculation. + +_**Data type:** Integer_ + +## Examples + +#### Calculate a five point triple exponential derivative +```js +from(bucket: "example-bucket"): + |> range(start: -12h) + |> tripleExponentialDerivative(n: 5) +``` From 733fc6f13cb2e6272c64adabc6eb0f5677b6d6e9 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Mon, 12 Aug 2019 08:52:13 -0600 Subject: [PATCH 2/2] updated tripleExponentialDerivative to address PR feedback --- .../aggregates/tripleexponentialderivative.md | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/content/v2.0/reference/flux/functions/built-in/transformations/aggregates/tripleexponentialderivative.md b/content/v2.0/reference/flux/functions/built-in/transformations/aggregates/tripleexponentialderivative.md index fcc4df79e..1f734698c 100644 --- a/content/v2.0/reference/flux/functions/built-in/transformations/aggregates/tripleexponentialderivative.md +++ b/content/v2.0/reference/flux/functions/built-in/transformations/aggregates/tripleexponentialderivative.md @@ -2,7 +2,7 @@ title: tripleExponentialDerivative() function description: > The `tripleExponentialDerivative()` function calculates a triple exponential - derivative of input tables using `n` points. + derivative (TRIX) of input tables using `n` points. menu: v2_0_ref: name: tripleExponentialDerivative @@ -19,7 +19,8 @@ related: --- The `tripleExponentialDerivative()` function calculates a triple exponential -derivative of input tables using `n` points. +derivative ([TRIX](https://en.wikipedia.org/wiki/Trix_(technical_analysis)) of +input tables using `n` points. _**Function type:** Aggregate_ @@ -28,15 +29,16 @@ tripleExponentialDerivative(n: 5) ``` Triple exponential derivative, commonly referred to as “TRIX,” is a momentum indicator and oscillator. -A triple exponential derivative is a triple exponential moving average of the log of data input over the period of time. -It prevents cycles shorter than the defined period from being considered by the indicator. -With `tripleExponentialDerivative()`, the period of time is determined by the time `n` points span. +A triple exponential derivative uses the natural logarithm (log) of input data to +calculate a triple exponential moving average over the period of time. +The calculation prevents cycles shorter than the defined period from being considered by the indicator. +`tripleExponentialDerivative()` uses the time between `n` points to define the period. Triple exponential derivative oscillates around a zero line. -When used as a momentum **oscillator**, a positive value indicates an overbought market -and a negative value indicates an oversold market. -When used as a momentum **indicator**, a positive value suggests momentum is -increasing and a negative value suggests momentum is decreasing. +A positive momentum **oscillator** value indicates an overbought market; +a negative value indicates an oversold market. +A positive momentum **indicator** value indicates increasing momentum; +a negative value indicates decreasing momentum. ##### Triple exponential moving average rules - A triple exponential derivative is defined as: @@ -44,10 +46,9 @@ increasing and a negative value suggests momentum is decreasing. - `EMA_3 = EMA(EMA(EMA(data)))` - If there are not enough values to calculate a triple exponential derivative, the output `_value` is `NaN`; all other columns are the same as the _last_ record of the input table. -- The behavior of the exponential moving averages used for calculating the triple - exponential derivative is the same as [`exponentialMovingAverage`](/v2.0/reference/flux/functions/built-in/transformations/aggregates/exponentialmovingaverage/): - - `tripleExponentialDerivative` ignores `null` values and does not inlcude them in the calculation. - - It acts only on the `_value` column. +- The function behaves the same way as the [`exponentialMovingAverage()`](/v2.0/reference/flux/functions/built-in/transformations/aggregates/exponentialmovingaverage/) function: + - The function does not include `null` values in the calculation. + - The function acts only on the `_value` column. ## Parameters