Technical analysis functions

Updated at:
Copy as MD

Technical analysis functions apply widely used financial algorithms to time-series data. Although these functions originate in finance and investment, they work equally well in other domains such as IoT monitoring and infrastructure observability.

Shared parameters

All technical analysis functions accept a field key argument plus the following shared parameters.

PERIOD

Required. Type: INT. Minimum: 1.

The sample size of the algorithm — the number of historical data points that have a significant effect on the output. For example, PERIOD=2 means the current point and its immediately preceding point.

The algorithm uses an exponential decay rate, known as alpha (α), to weight historical points. The decay rate is controlled by PERIOD.

HOLD_PERIOD

Type: INT. Minimum: -1. Default: -1.

The number of samples the algorithm must process before it starts emitting results. The default value -1 tells the algorithm to derive HOLD_PERIOD automatically from the combination of the algorithm, PERIOD, and WARMUP_TYPE.

Default hold periods by algorithm and warmup type:

Algorithmsimpleexponentialnone
EXPONENTIAL_MOVING_AVERAGEPERIOD - 1PERIOD - 1n/a
DOUBLE_EXPONENTIAL_MOVING_AVERAGE(PERIOD - 1) × 2PERIOD - 1n/a
TRIPLE_EXPONENTIAL_MOVING_AVERAGE(PERIOD - 1) × 3PERIOD - 1n/a
TRIPLE_EXPONENTIAL_DERIVATIVE(PERIOD - 1) × 3 + 1PERIODn/a
RELATIVE_STRENGTH_INDEXPERIODPERIODn/a
CHANDE_MOMENTUM_OSCILLATORPERIODPERIODPERIOD - 1

Default hold periods for Kaufman algorithms:

AlgorithmDefault hold period
KAUFMANS_EFFICIENCY_RATIO()PERIOD
KAUFMANS_ADAPTIVE_MOVING_AVERAGE()PERIOD

WARMUP_TYPE

Default: `exponential`.

Controls how the algorithm initializes itself during the first PERIOD samples — in other words, how it handles an incomplete sample set at the start.

ValueBehaviorTa-Lib equivalent
simpleUses the simple moving average (SMA) of the first PERIOD samples.Yes
exponentialUses an exponential moving average (EMA) with a scaling alpha (α). The effective period starts at 1 for the first point and increments by 1 until it reaches PERIOD. Because EMA is used during initialization, the algorithm can emit output before the sample count reaches what simple would require — provided HOLD_PERIOD is not set or is set to -1.No
noneNo smoothing during initialization. When HOLD_PERIOD is unspecified, it defaults to PERIOD - 1.Yes
The none warmup type is only supported by CHANDE_MOMENTUM_OSCILLATOR().

CHANDE_MOMENTUM_OSCILLATOR()

The Chande Momentum Oscillator (CMO) is a technical momentum indicator developed by Tushar Chande. It subtracts the sum of recent down-moves from the sum of recent up-moves, divides by the total absolute movement over the period, and multiplies by 100. The result oscillates between -100 and +100.

Syntax:

CHANDE_MOMENTUM_OSCILLATOR([*|<field_key>|/regular_expression/], <period>[, <hold_period>[, <warmup_type>]])

Parameters: period (required), hold_period (optional), warmup_type (optional, supports simple, exponential, and none).

Supported field value types: INT64, FLOAT64.

Usage:

CHANDE_MOMENTUM_OSCILLATOR(field_key, 2) Returns the CMO of the field values for the specified field key, using a period of 2 with the default hold period and warmup type.

CHANDE_MOMENTUM_OSCILLATOR(field_key, 10, 9, 'none') Returns the CMO of the field values for the specified field key, using a period of 10, a hold period of 9, and warmup type none.

CHANDE_MOMENTUM_OSCILLATOR(MEAN(<field_key>), 2) ... GROUP BY time(1d) Returns the CMO of the daily mean field values for the specified field key, using a period of 2 with the default hold period and warmup type.

CHANDE_MOMENTUM_OSCILLATOR(/regular_expression/, 2) Returns the CMO of the field values for each field key matching the regular expression, using a period of 2 with the default hold period and warmup type.

CHANDE_MOMENTUM_OSCILLATOR(*, 2) Returns the CMO of the field values for every field key in the measurement, using a period of 2 with the default hold period and warmup type.

When using GROUP BY to aggregate data, include an aggregate function (such as MEAN()) in the call to CHANDE_MOMENTUM_OSCILLATOR().

EXPONENTIAL_MOVING_AVERAGE()

An exponential moving average (EMA) weights recent data more heavily than older data, unlike a simple moving average (SMA) which treats all points equally. Because it responds faster to recent changes, EMA is also called an exponentially weighted moving average.

Syntax:

EXPONENTIAL_MOVING_AVERAGE([*|<field_key>|/regular_expression/], <period>[, <hold_period>[, <warmup_type>]])

Parameters: period (required), hold_period (optional), warmup_type (optional).

Supported field value types: INT64, FLOAT64.

Usage:

EXPONENTIAL_MOVING_AVERAGE(field_key, 2) Returns the EMA of the field values for the specified field key, using a period of 2 with the default hold period and warmup type.

EXPONENTIAL_MOVING_AVERAGE(field_key, 10, 9, 'exponential') Returns the EMA of the field values for the specified field key, using a period of 10, a hold period of 9, and warmup type exponential.

EXPONENTIAL_MOVING_AVERAGE(MEAN(<field_key>), 2) ... GROUP BY time(1d) Returns the EMA of the daily mean field values for the specified field key, using a period of 2 with the default hold period and warmup type.

EXPONENTIAL_MOVING_AVERAGE(/regular_expression/, 2) Returns the EMA of the field values for each field key matching the regular expression, using a period of 2 with the default hold period and warmup type.

EXPONENTIAL_MOVING_AVERAGE(*, 2) Returns the EMA of the field values for every field key in the measurement, using a period of 2 with the default hold period and warmup type.

When using GROUP BY to aggregate data, include an aggregate function (such as MEAN()) in the call to EXPONENTIAL_MOVING_AVERAGE().

DOUBLE_EXPONENTIAL_MOVING_AVERAGE()

The Double Exponential Moving Average (DEMA) reduces the lag inherent in standard moving averages by applying a composite formula rather than simply smoothing twice. The formula is:

DEMA = 2 × EMA − EMA(EMA)

This doubles the EMA and subtracts a smoothed EMA from it, keeping output closer to actual data while minimizing delay.

Syntax:

DOUBLE_EXPONENTIAL_MOVING_AVERAGE([*|<field_key>|/regular_expression/], <period>[, <hold_period>[, <warmup_type>]])

Parameters: period (required), hold_period (optional), warmup_type (optional).

Supported field value types: INT64, FLOAT64.

Usage:

DOUBLE_EXPONENTIAL_MOVING_AVERAGE(field_key, 2) Returns the DEMA of the field values for the specified field key, using a period of 2 with the default hold period and warmup type.

DOUBLE_EXPONENTIAL_MOVING_AVERAGE(field_key, 10, 9, 'exponential') Returns the DEMA of the field values for the specified field key, using a period of 10, a hold period of 9, and warmup type exponential.

DOUBLE_EXPONENTIAL_MOVING_AVERAGE(MEAN(<field_key>), 2) ... GROUP BY time(1d) Returns the DEMA of the daily mean field values for the specified field key, using a period of 2 with the default hold period and warmup type.

DOUBLE_EXPONENTIAL_MOVING_AVERAGE(/regular_expression/, 2) Returns the DEMA of the field values for each field key matching the regular expression, using a period of 2 with the default hold period and warmup type.

DOUBLE_EXPONENTIAL_MOVING_AVERAGE(*, 2) Returns the DEMA of the field values for every field key in the measurement, using a period of 2 with the default hold period and warmup type.

When using GROUP BY to aggregate data, include an aggregate function (such as MEAN()) in the call to DOUBLE_EXPONENTIAL_MOVING_AVERAGE().

TRIPLE_EXPONENTIAL_MOVING_AVERAGE()

The Triple Exponential Moving Average (TEMA) filters out short-term fluctuations more aggressively than a single EMA or DEMA. Despite the name, TEMA is not calculated by applying exponential smoothing three times. Instead, it uses a composite of EMA, DEMA, and TEMA values to produce a smoother, lower-lag result.

Syntax:

TRIPLE_EXPONENTIAL_MOVING_AVERAGE([*|<field_key>|/regular_expression/], <period>[, <hold_period>[, <warmup_type>]])

Parameters: period (required), hold_period (optional), warmup_type (optional).

Supported field value types: INT64, FLOAT64.

Usage:

TRIPLE_EXPONENTIAL_MOVING_AVERAGE(field_key, 2) Returns the TEMA of the field values for the specified field key, using a period of 2 with the default hold period and warmup type.

TRIPLE_EXPONENTIAL_MOVING_AVERAGE(field_key, 10, 9, 'exponential') Returns the TEMA of the field values for the specified field key, using a period of 10, a hold period of 9, and warmup type exponential.

TRIPLE_EXPONENTIAL_MOVING_AVERAGE(MEAN(<field_key>), 2) ... GROUP BY time(1d) Returns the TEMA of the daily mean field values for the specified field key, using a period of 2 with the default hold period and warmup type.

TRIPLE_EXPONENTIAL_MOVING_AVERAGE(/regular_expression/, 2) Returns the TEMA of the field values for each field key matching the regular expression, using a period of 2 with the default hold period and warmup type.

TRIPLE_EXPONENTIAL_MOVING_AVERAGE(*, 2) Returns the TEMA of the field values for every field key in the measurement, using a period of 2 with the default hold period and warmup type.

When using GROUP BY to aggregate data, include an aggregate function (such as MEAN()) in the call to TRIPLE_EXPONENTIAL_MOVING_AVERAGE().

TRIPLE_EXPONENTIAL_DERIVATIVE()

The Triple Exponential Derivative indicator (TRIX) is an oscillator that identifies overbought and oversold conditions in a dataset. It applies TEMA to the logarithm of the input data over the specified period, then subtracts the previous value from the current one. This effectively filters out cycles shorter than the given period.

TRIX oscillates around a zero line:

  • As an oscillator: a positive value indicates an overbought condition; a negative value indicates an oversold condition.

  • As a momentum indicator: a positive value indicates increasing momentum; a negative value indicates decreasing momentum.

  • Values crossing above the zero line are interpreted as buy signals; values crossing below are interpreted as sell signals.

Syntax:

TRIPLE_EXPONENTIAL_DERIVATIVE([*|<field_key>|/regular_expression/], <period>[, <hold_period>[, <warmup_type>]])

Parameters: period (required), hold_period (optional), warmup_type (optional).

Supported field value types: INT64, FLOAT64.

Usage:

TRIPLE_EXPONENTIAL_DERIVATIVE(field_key, 2) Returns the TRIX of the field values for the specified field key, using a period of 2 with the default hold period and warmup type.

TRIPLE_EXPONENTIAL_DERIVATIVE(field_key, 10, 10, 'exponential') Returns the TRIX of the field values for the specified field key, using a period of 10, a hold period of 10, and warmup type exponential.

TRIPLE_EXPONENTIAL_DERIVATIVE(MEAN(<field_key>), 2) ... GROUP BY time(1d) Returns the TRIX of the daily mean field values for the specified field key, using a period of 2 with the default hold period and warmup type.

TRIPLE_EXPONENTIAL_DERIVATIVE(/regular_expression/, 2) Returns the TRIX of the field values for each field key matching the regular expression, using a period of 2 with the default hold period and warmup type.

TRIPLE_EXPONENTIAL_DERIVATIVE(*, 2) Returns the TRIX of the field values for every field key in the measurement, using a period of 2 with the default hold period and warmup type.

When using GROUP BY to aggregate data, include an aggregate function (such as MEAN()) in the call to TRIPLE_EXPONENTIAL_DERIVATIVE().

KAUFMANS_EFFICIENCY_RATIO()

Kaufman's Efficiency Ratio (ER), introduced by Perry Kaufman, measures how efficiently a market is moving by dividing the net price change over a period by the sum of all absolute price movements during that period. ER ranges from 0 to 1: a value closer to 1 indicates a strongly trending, efficient market; a value closer to 0 indicates a noisy, range-bound market.

ER is mathematically related to the Chande Momentum Oscillator (CMO): dividing the absolute value of CMO by 100 gives the equivalent ER value. The difference is that CMO also captures market direction.

Syntax:

KAUFMANS_EFFICIENCY_RATIO([*|<field_key>|/regular_expression/], <period>[, <hold_period>])

Parameters: period (required), hold_period (optional).

Supported field value types: INT64, FLOAT64.

Usage:

KAUFMANS_EFFICIENCY_RATIO(field_key, 2) Returns the ER of the field values for the specified field key, using a period of 2 with the default hold period.

KAUFMANS_EFFICIENCY_RATIO(field_key, 10, 10) Returns the ER of the field values for the specified field key, using a period of 10 and a hold period of 10.

KAUFMANS_EFFICIENCY_RATIO(MEAN(<field_key>), 2) ... GROUP BY time(1d) Returns the ER of the daily mean field values for the specified field key, using a period of 2 with the default hold period.

KAUFMANS_EFFICIENCY_RATIO(/regular_expression/, 2) Returns the ER of the field values for each field key matching the regular expression, using a period of 2 with the default hold period.

KAUFMANS_EFFICIENCY_RATIO(*, 2) Returns the ER of the field values for every field key in the measurement, using a period of 2 with the default hold period.

When using GROUP BY to aggregate data, include an aggregate function (such as MEAN()) in the call to KAUFMANS_EFFICIENCY_RATIO().

KAUFMANS_ADAPTIVE_MOVING_AVERAGE()

Kaufman's Adaptive Moving Average (KAMA) adjusts its sensitivity based on the noise level in the data. When volatility is low and the signal is clean, KAMA tracks price closely. When volatility is high and data is noisy, KAMA slows down to filter out noise. Use KAMA to identify overall trends, detect turning points, and reduce the impact of short-term fluctuations.

Syntax:

KAUFMANS_ADAPTIVE_MOVING_AVERAGE([*|<field_key>|/regular_expression/], <period>[, <hold_period>])

Parameters: period (required), hold_period (optional).

Supported field value types: INT64, FLOAT64.

Usage:

KAUFMANS_ADAPTIVE_MOVING_AVERAGE(field_key, 2) Returns the KAMA of the field values for the specified field key, using a period of 2 with the default hold period.

KAUFMANS_ADAPTIVE_MOVING_AVERAGE(field_key, 10, 10) Returns the KAMA of the field values for the specified field key, using a period of 10 and a hold period of 10.

KAUFMANS_ADAPTIVE_MOVING_AVERAGE(MEAN(<field_key>), 2) ... GROUP BY time(1d) Returns the KAMA of the daily mean field values for the specified field key, using a period of 2 with the default hold period.

KAUFMANS_ADAPTIVE_MOVING_AVERAGE(/regular_expression/, 2) Returns the KAMA of the field values for each field key matching the regular expression, using a period of 2 with the default hold period.

KAUFMANS_ADAPTIVE_MOVING_AVERAGE(*, 2) Returns the KAMA of the field values for every field key in the measurement, using a period of 2 with the default hold period.

When using GROUP BY to aggregate data, include an aggregate function (such as MEAN()) in the call to KAUFMANS_ADAPTIVE_MOVING_AVERAGE().

RELATIVE_STRENGTH_INDEX()

The Relative Strength Index (RSI) is a momentum indicator that measures the magnitude of recent data changes over a given period. RSI evaluates both the speed and scale of those changes, making it useful for identifying when a value has moved too far, too fast.

Syntax:

RELATIVE_STRENGTH_INDEX([*|<field_key>|/regular_expression/], <period>[, <hold_period>[, <warmup_type>]])

Parameters: period (required), hold_period (optional), warmup_type (optional).

Supported field value types: INT64, FLOAT64.

Usage:

RELATIVE_STRENGTH_INDEX(field_key, 2) Returns the RSI of the field values for the specified field key, using a period of 2 with the default hold period and warmup type.

RELATIVE_STRENGTH_INDEX(field_key, 10, 10, 'exponential') Returns the RSI of the field values for the specified field key, using a period of 10, a hold period of 10, and warmup type exponential.

RELATIVE_STRENGTH_INDEX(MEAN(<field_key>), 2) ... GROUP BY time(1d) Returns the RSI of the daily mean field values for the specified field key, using a period of 2 with the default hold period and warmup type.

RELATIVE_STRENGTH_INDEX(/regular_expression/, 2) Returns the RSI of the field values for each field key matching the regular expression, using a period of 2 with the default hold period and warmup type.

RELATIVE_STRENGTH_INDEX(*, 2) Returns the RSI of the field values for every field key in the measurement, using a period of 2 with the default hold period and warmup type.

When using GROUP BY to aggregate data, include an aggregate function (such as MEAN()) in the call to RELATIVE_STRENGTH_INDEX().