All Products
Search
Document Center

Time Series Database:Technical analysis functions

Last Updated:Jul 28, 2021

Technical analysis functions can be used to apply widely used algorithms to your data. In most cases, these functions are used in the finance and investment industries. However, these functions can also be applied to other industries and scenarios. This topic describes the syntax and parameters of technical analysis functions. It also provides multiple examples.

Parameters

In addition to the field key parameter, technical analysis functions also provide the following parameters.

  • PERIOD

    This parameter is required. Data type: INT. Minimum value: 1. This parameter specifies the sample size of the algorithm. This parameter specifies the number of historical samples that have a significant impact on the algorithm outputs. For example, the value 2 indicates two points: the current point and its previous point. The algorithm uses an exponential decay rate to specify the weight of a historical point. This is known as alpha(α). The decay rate is subject to the PERIOD parameter. Note: Historical points affect the algorithm outputs.

  • HOLD_PERIOD

    Data type: INT. Minimum value: -1. This parameter specifies the number of samples that are required by your algorithm to start generating an output. The default value -1 indicates that the value of the HOLD_PERIOD parameter is based on your algorithm, the PERIOD parameter, and the WARMUP_TYPE parameter. In this case, the value of the HOLD_PERIOD parameter is used by the algorithm to generate useful results.

    Default hold periods: In technical analysis cases, the default value of the HOLD_PERIOD parameter is subject to your technical analysis algorithm and the WARMUP_TYPE parameter.

    Algorithm or warmup type

    simple

    exponential

    none

    EXPONENTIAL_MOVING_AVERAGE

    PERIOD - 1

    PERIOD - 1

    n/a

    DOUBLE_EXPONENTIAL_MOVING_AVERAGE

    ( PERIOD - 1 ) * 2

    PERIOD - 1

    n/a

    TRIPLE_EXPONENTIAL_MOVING_AVERAGE

    ( PERIOD - 1 ) * 3

    PERIOD - 1

    n/a

    TRIPLE_EXPONENTIAL_DERIVATIVE

    ( PERIOD - 1 ) * 3 + 1

    PERIOD

    n/a

    RELATIVE_STRENGTH_INDEX

    PERIOD

    PERIOD

    n/a

    CHANDE_MOMENTUM_OSCILLATOR

    PERIOD

    PERIOD

    PERIOD - 1

    Default hold period that is used by the Kaufman algorithms

    Algorithm

    Default hold period

    KAUFMANS_EFFICIENCY_RATIO()

    PERIOD

    KAUFMANS_ADAPTIVE_MOVING_AVERAGE()

    PERIOD

  • WARMUP_TYPE

    Default value: exponential. This parameter specifies how an algorithm initializes itself for the first PERIOD samples. In practice, this parameter specifies the duration of an incomplete sample set that is processed.

    simple: indicates the simple moving average (SMA) of the first PERIOD samples. This method is used by the Ta-Lib library.

    exponential: indicates that the exponential moving average (EMA) is calculated based on a specified scaling alpha (α). Basic usage of the EMA metric: set the PERIOD parameter to 1 for the first point, set the PERIOD parameter to 2 for the second point, and then repeat this operation until the algorithm processes PERIOD points. The algorithm may generate points when the sample size is much smaller than the sample size that is specified by the simple parameter. This occurs when the following conditions are met: 1. The EMA is used by the algorithm in the initial stage. 2. The preceding method is used. 3. The HOLD_PERIOD parameter is not set or is set to -1.

    none: indicates that the algorithm does not perform a smoothing operation. This method is used by the Ta-Lib library. If this method is used and the HOLD_PERIOD parameter is not specified, the default value of the HOLD_PERIOD parameter is PERIOD - 1.

    Note

    The none warmup type is applicable only to the CHANDE_MOMENTUM_OSCILLATOR() function.

CHANDE_MOMENTUM_OSCILLATOR()

The Chande Momentum Oscillator (CMO) metric is a technical momentum metric that is developed by Tushar Chande. To calculate a CMO metric value, calculate the difference between the sum for all of the most recent larger points and the sum for all of the most recent smaller points. Then, divide the difference by the sum of the data movements in a specified time range. Multiply the result by 100 to obtain a range from -100 to +100.

Basic syntax

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

Parameters

Available parameters include period, hold_period (optional), and warmup_type (optional).

Description

The CHANDE_MOMENTUM_OSCILLATOR(field_key, 2) function is used to implement the CMO algorithm on the field values of the specified field key. In the CMO algorithm, the period is set to 2. The default hold period and the default warmup type are used.

The CHANDE_MOMENTUM_OSCILLATOR(field_key, 10, 9, 'none') function is used to implement the CMO algorithm on the field values of the specified field key. In the CMO algorithm, the period is set to 2, the hold period is set to 9, and the warmup type is set to none.

CHANDE_MOMENTUM_OSCILLATOR(MEAN(<field_key>), 2) ... The GROUP BY time(1d) clause is used to implement the CMO algorithm on the average field values of the specified field key. In the CMO algorithm, the period is set to 2. The default hold period and the default warmup type are used.

Note

Notes: If you use the GROUP BY clause to aggregate data, you must include an aggregate function in your request to call the CHANDE_MOMENTUM_OSCILLATOR() function.

The CHANDE_MOMENTUM_OSCILLATOR(/regular_expression/, 2) function is used to implement the CMO algorithm on the field values of each field key that matches the specified regular expression. In the CMO algorithm, the period is set to 2. The default hold period and the default warmup type are used.

The CHANDE_MOMENTUM_OSCILLATOR(*, 2) function is used to implement the CMO algorithm on the field values of each field key for the specified measurement. In the CMO algorithm, the period is set to 2. The default hold period and the default warmup type are used.

The CHANDE_MOMENTUM_OSCILLATOR() function supports INT64 and FLOAT64 field values.

EXPONENTIAL_MOVING_AVERAGE()

An exponential moving average (EMA) is similar to an SMA. The difference is that an EMA places more weight on the latest data than an SMA. Therefore, an EMA is also known as an exponential weighted moving average. An EMA responds faster to recent data changes than an SMA.

Basic syntax

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

Parameters

Applicable parameters include period, hold_period (optional), and warmup_type (optional).

Description

The EXPONENTIAL_MOVING_AVERAGE(field_key, 2) function is used to implement the EMA algorithm on the average field values of the specified field key. In the EMA algorithm, the period is set to 2. The default hold period and the default warmup type are used.

The EXPONENTIAL_MOVING_AVERAGE(field_key, 10, 9, 'exponential') function is used to implement the EMA algorithm on the average field values of the specified field key. In the EMA algorithm, the period is set to 2, the hold period is set to 10, and the hold period is set to exponential.

EXPONENTIAL_MOVING_AVERAGE(MEAN(<field_key>), 2) ... The GROUP BY time(1d) clause is used to implement the EMA algorithm on the average field values of the specified field key. In the EMA algorithm, the period is set to 2. The default hold period and the default warmup type are used.

Note

Notes: If you use the GROUP BY clause to aggregate data, you must include an aggregate function in your request to call the KAUFMANS_ADAPTIVE_MOVING_AVERAGE() function.

The EXPONENTIAL_MOVING_AVERAGE(/regular_expression/, 2) function is used to implement the EMA algorithm on the field values of each field key that matches the specified regular expression. In the EMA algorithm, the period is set to 2. The default hold period and the default warmup type are used.

The EXPONENTIAL_MOVING_AVERAGE(*, 2) function is used to implement the EMA algorithm on the field values of each field key for the specified measurement. In the EMA algorithm, the period is set to 2. The default hold period and the default warmup type are used.

The EXPONENTIAL_MOVING_AVERAGE() function supports INT64 and FLOAT64 field values.

DOUBLE_EXPONENTIAL_MOVING_AVERAGE()

The Double Exponential Moving Average (DEMA) metric is used to increase the weight of the most recent data and remove the inherent lag that is related to moving averages. The metric name implies that a DEMA is calculated by implementing double exponential smoothing. However, in practice, the name double indicates that the metric is used to double an EMA. You can subtract a smoothed EMA from a doubled EMA. This can be used to ensure consistency with the actual data and minimize latency. The formula is DEMA = 2 × EMA - EMA(EMA).

Basic syntax

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

Parameters

Applicable parameters include period, hold_period (optional), and warmup_type (optional).

Description

The DOUBLE_EXPONENTIAL_MOVING_AVERAGE(field_key, 2) function is used to implement the DEMA algorithm on the field values of the specified field key. In the algorithm, the period is set to 2. The default hold period and the default warmup type are used.

The DOUBLE_EXPONENTIAL_MOVING_AVERAGE(field_key, 10, 9, 'exponential') function is used to implement the DEMA algorithm on the field values of the specified field key. In the algorithm, the period is set to 10, the hold period is set to 9, and the warmup type is set to exponential.

DOUBLE_EXPONENTIAL_MOVING_AVERAGE(MEAN(<field_key>), 2) ... The GROUP BY time(1d) clause is used to implement the DEMA algorithm on the field values of the specified field key. In the algorithm, the period is set to 2. The default hold period and the default warmup type are used.

Note

Notes: If you use the GROUP BY clause to aggregate data, you must specify an aggregate function in your request to call the DOUBLE_EXPONENTIAL_MOVING_AVERAGE() function.

The DOUBLE_EXPONENTIAL_MOVING_AVERAGE(/regular_expression/, 2) function is used to implement the DEMA algorithm on the field values of each field key that matches the specified regular expression. In the algorithm, the period is set to 2. The default hold period and the default warmup type are used.

The DOUBLE_EXPONENTIAL_MOVING_AVERAGE(*, 2) function implements the DEMA algorithm on the field values of each field key for the specified measurement. In the algorithm, the period is set to 2. The default hold period and the default warmup type are used.

The DOUBLE_EXPONENTIAL_MOVING_AVERAGE() function supports INT64 and FLOAT64 field values.

KAUFMANS_EFFICIENCY_RATIO()

The efficiency ratio (ER) metric is introduced by Perry Kaufman. To calculate an ER, divide the data change over a specified period of time by the sum of the absolute data movements that cause the change. An ER ranges between 0 and 1. A higher ER indicates a more efficient or trending market.

An ER is similar to a CMO. The difference is that a CMO takes the market direction into account. If you divide the absolute value of a CMO by 100, you can obtain the related ER.

Basic syntax

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

Parameters

Available parameters include period and hold_period (optional).

Description

The KAUFMANS_EFFICIENCY_RATIO(field_key, 2) function is used to implement the efficiency index algorithm on the field values of the specified field key. In the algorithm, the period is set to 2. The default hold period and the default warmup type are used.

The KAUFMANS_EFFICIENCY_RATIO(field_key, 10, 10) function is used to implement the efficiency index algorithm on the field values of the specified field key. In the algorithm, the period is set to 10 and the hold period is set to 10.

KAUFMANS_EFFICIENCY_RATIO(MEAN(<field_key>), 2) ... The GROUP BY time(1d) clause is used to implement the efficiency index algorithm on the average field values of the specified field key. In the algorithm, the period is set to 2. The default hold period is used.

Note

Note: If you use the GROUP BY clause to aggregate data, you must specify an aggregate function in your request to call the KAUFMANS_EFFICIENCY_RATIO() function.

The KAUFMANS_EFFICIENCY_RATIO(/regular_expression/, 2) function is used to implement the efficiency index algorithm on the field values of each field key that matches the specified regular expression. In the algorithm, the period is set to 2. The default hold period is used.

KAUFMANS_EFFICIENCY_RATIO(*, 2) function is used to implement the efficiency index algorithm on the field values of each field key for the specified measurement. In the algorithm, the period is set to 2. The default hold period is used.

The KAUFMANS_EFFICIENCY_RATIO() function supports INT64 and FLOAT64 field values.

KAUFMANS_ADAPTIVE_MOVING_AVERAGE()

Kaufman's Adaptive Moving Average (KAMA) is a moving average that represents the noise or volatility of samples. If data fluctuations are small and the noise is low, the KAMA metric responds to the sample points in an active way. If data fluctuations are large, the KAMA metric is adjusted to reduce the noise impacts. You can use this trend-following metric to identify the overall trends, time turning points, and filter data movements.

Basic syntax

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

Parameters

Available parameters include period, hold_period (optional), and warmup_type (optional).

Description

The KAUFMANS_ADAPTIVE_MOVING_AVERAGE(field_key, 2) function is used to implement the KAMA algorithm on the field values of the specified field key. In the algorithm, the period is set to 2. The default hold period is used.

KAUFMANS_ADAPTIVE_MOVING_AVERAGE(field_key, 10, 10) function is used to implement the KAMA algorithm on the field values of the specified field key. In the algorithm, the period is set to 10 and the hold period is set to 10.

KAUFMANS_ADAPTIVE_MOVING_AVERAGE(MEAN(<field_key>), 2) ... The GROUP BY time(1d) clause is used to implement the KAMA algorithm on the average field values of the specified field key. In the algorithm, the period is set to 2. The default hold period is used.

Note

Note: If you use the GROUP BY clause to aggregate data, you must specify an aggregate function in your request to call the KAUFMANS_ADAPTIVE_MOVING_AVERAGE() function.

KAUFMANS_ADAPTIVE_MOVING_AVERAGE(/regular_expression/, 2) function is used to implement the KAMA algorithm on the field values of each field key that matches the specified regular expression. In the algorithm, the period is set to 2. The default hold period is used.

The KAUFMANS_ADAPTIVE_MOVING_AVERAGE(*, 2) function is used to implement the KAMA algorithm on the field values of each field key for the specified measurement. In the algorithm, the period is set to 2. The default hold period is used.

The KAUFMANS_ADAPTIVE_MOVING_AVERAGE() function supports INT64 and FLOAT64 field values.

TRIPLE_EXPONENTIAL_MOVING_AVERAGEE()

The triple exponential moving average (TEMA) metric is designed to filter out the fluctuations of traditional moving averages. The name implies that you can implement triple exponential smoothing to calculate a TEMA. However, you cannot implement triple exponential smoothing to calculate the TEMA. In this case, triple indicates a composite function that contains an EMA, a DEMA, and a TEMA.

Basic syntax

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

Parameters

Available parameters include period, hold_period (optional), and warmup_type (optional).

Description

The TRIPLE_EXPONENTIAL_MOVING_AVERAGE(field_key, 2) function is used to implement the TEMA algorithm on the field values of each field key for the specified measurement. In the algorithm, the period is set to 2. The default hold period is used.

TRIPLE_EXPONENTIAL_MOVING_AVERAGE(field_key, 10, 9, 'exponential') function is used to implement the TEMA algorithm on the field values of each field key for the specified measurement. In the algorithm, the period is set to 10, the hold period is set to 9, and the warmup type is set to exponential.

TRIPLE_EXPONENTIAL_MOVING_AVERAGE(MEAN(<field_key>), 2) ... The GROUP BY time(1d) clause is used to implement the TEMA algorithm on the average field values of the specified field key. In the algorithm, the period is set to 2. The default hold period and warmup type are used.

Note

Note: If you use the GROUP BY clause to aggregate data, you must specify an aggregate function in your request to call the TRIPLE_EXPONENTIAL_MOVING_AVERAGE() function.

The TRIPLE_EXPONENTIAL_MOVING_AVERAGE(/regular_expression/, 2) function is used to implement the TEMA algorithm on the field values of each field key that matches the specified regular expression. In the algorithm, the period is set to 2. The default hold period and warmup type are used.

The TRIPLE_EXPONENTIAL_MOVING_AVERAGE(*, 2) function is used to implement the TEMA algorithm on the field values of each field key for the specified measurement. In the algorithm, the period is set to 2. The default hold period and warmup type are used.

The TRIPLE_EXPONENTIAL_MOVING_AVERAGE() function supports INT64 and FLOAT64 field values.

TRIPLE_EXPONENTIAL_DERIVATIVE()

The triple exponential derivative indicator (TRIX) is an oscillator that is used to identify oversold and overbought markets. The TRIX can also be used as a momentum metric. The TRIX calculates the TEMA of logarithms for the input data over a period of time. The previous value is subtracted from the current value. In this case, TRIX excludes the periods that are shorter than the specified period.

Same as many oscillators, the TRIX oscillates around the zero line. When the TRIX is used as an oscillator, a positive value indicates an overbought market and a negative value indicates an oversold market. When the TRIX is used as a momentum metric, a positive value indicates an increasing momentum and a negative value indicates a decreasing momentum. Many analysts believe that a TRIX value above the zero line indicates a buy signal and a TRIX value below the zero line indicates a sell signal.

Basic syntax

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

Parameters

Available parameters include period, hold_period (optional), and warmup_type (optional).

Description

The TRIPLE_EXPONENTIAL_DERIVATIVE(field_key, 2) function is used to implement the TRIX algorithm on the field values of the specified field key. In the algorithm, the period is set to 2. The default hold period and warmup type are used.

The TRIPLE_EXPONENTIAL_DERIVATIVE(field_key, 10, 10, 'exponential') function is used to implement the TRIX algorithm on the field values of the specified field key. In the algorithm, the period is set to 10, the hold period is set to 10, and the warmup type is set to exponential.

TRIPLE_EXPONENTIAL_DERIVATIVE(MEAN(<field_key>), 2) ... The GROUP BY time(1d) clause is used to implement the TRIX algorithm on the average field values of the specified field key. In the algorithm, the period is set to 2. The default hold period and warmup type are used.

Note

Note: If you use the GROUP BY clause to aggregate data, you must specify an aggregate function in your request to call the TRIPLE_EXPONENTIAL_DERIVATIVE() function.

The TRIPLE_EXPONENTIAL_DERIVATIVE(/regular_expression/, 2) function is used to implement the TRIX algorithm on the field values of each field key that matches the specified regular expression. In the algorithm, the period is set to 2. The default hold period and warmup type are used.

The TRIPLE_EXPONENTIAL_DERIVATIVE(*, 2) function is used to implement the TRIX algorithm on the field values of each field key for the specified measurement. In the algorithm, the period is set to 2. The default hold period and warmup type are used.

The TRIPLE_EXPONENTIAL_DERIVATIVE() function supports INT64 and FLOAT64 field values.

RELATIVE_STRENGTH_INDEX()

The relative strength index (RSI) is a momentum metric that measures the magnitude of recent data changes over a specified time period. You can use this metric to evaluate the speed and the change of data movements.

Basic syntax

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

Parameters

Available parameters include period, hold_period (optional), and warmup_type (optional).

Description

The RELATIVE_STRENGTH_INDEX(field_key, 2) function is used to implement the RSI algorithm on the field values of the specified field key. In the algorithm, the period is set to 2, and the default hold period and the default warmup type are used.

The RELATIVE_STRENGTH_INDEX(field_key, 10, 10, 'exponential') function is used to implement the RSI algorithm on the field values of the specified field key. In the algorithm, the period is set to 10, the hold period is set to 10, and the warmup type is set to exponential.

RELATIVE_STRENGTH_INDEX(MEAN(<field_key>), 2) ... The GROUP BY time(1d) clause is used to implement the RSI algorithm on the average field values of the specified field key. In the algorithm, the period is set to 2. The default hold period and the default warmup type are used.

Note

Note: If you use the GROUP BY clause to aggregate data, you must specify an aggregate function in your request to call the RELATIVE_STRENGTH_INDEX() function.

The RELATIVE_STRENGTH_INDEX(/regular_expression/, 2) function is used to implement the RSI algorithm on the field values of each field key that matches the specified regular expression. In the algorithm, the period is set to 2. The default hold period and the default warmup type are used.

The RELATIVE_STRENGTH_INDEX(*, 2) function is used to implement the RSI algorithm on the field values of each field key for the specified measurement. In the algorithm, the period is set to 2. The default hold period and the default warmup type are used.

The RELATIVE_STRENGTH_INDEX() function supports INT64 and FLOAT64 field values.