Investment Studio > Expressions > Functions > Indicator > TRIX

float array[*][2] trix(float array[*][2] dc, integer days, float previous_ema_1 = 0, float previous_ema_2 = 0, float previous_ema_3 = 0)

Returns a two-column array containing dates (first column) and corresponding Triple Exponentially Smoothed ROC (TRIX) values (second column). Given n input rows in dc, n - days (or fewer) rows are returned. Due to the triple exponential smoothing, roughly 10 * days rows of input are needed before output stabilizes.

dc is a two-column array containing dates (first column) and corresponding daily closes (second column). The array is assumed to be time-sorted, with earlier dates preceding later dates.

Automatic type conversion allows the use of date strings as arguments instead of explicit date values.

days sets the timescale of the ROC and of the three EMAs used to smooth its output.

previous_ema_1 is the value of the first EMA on the trading date preceding the first date quoted in dc. If omitted, it defaults to 0.

previous_ema_2 is the value of the second EMA on the trading date preceding the first date quoted in dc. If omitted, it defaults to 0.

previous_ema_3 is the value of the third EMA on the trading date preceding the first date quoted in dc. If omitted, it defaults to 0.

Interpretation

TRIX is a ROC(days) smoothed by three successive EMA(days):

TRIX = EMA(EMA(EMA(ROC(dc, days), days, previous_ema_1), days, previous_ema_2), days, previous_ema_3)

Its uses are the same as those of a plain or a simply smoothed ROC:

Trend determination: The price trend is up if TRIX > 0, down if TRIX < 0. Traders buy when the TRIX turns up from a bottom or on crossings above historical thresholds; they sell when the TRIX turns down from a top or on crossings below historical thresholds.
Divergences: When price and TRIX move in opposite directions, it's a warning that the price trend may be about to reverse.
Crossovers: A popular, MACD-like application is to buy when the TRIX crosses over its own 9 day MA and sell when the TRIX crosses below it.

The charts show a real life example, RedHat (NASD:RHAT) from January 1 to December 31, 2001:

The top chart shows prices in standard candlestick form, the bottom chart shows the 10 day TRIX (in red) and its 9 day MA (in blue). In the top chart, days marked in green are bullish crossovers (TRIX crossing above its 9 day MA); days marked in red are bearish crossovers or zero crossings (TRIX crossing below its 9 day MA or below zero).

The rationale beind the TRIX is simple: chaining three EMAs yields better suppression of shorter cycles and noise than using a single EMA of comparable length. This in turn means a lower risk of false signals and whipsaws.

To analyze the effect of the triple EMA smoothing, we can exploit the fact that the frequency response of any linear, time-invariant filter is just the Fourier transform of the filter's impulse response (the filter's output when the input sequence is a unit impulse, i.e. a single 1 surrounded by zeros, effectively all the way both to positive and to negative infinity). This means that we can visualize the frequency response of an EMA chain by passing a unit impulse through it and computing the Fourier transforms of its output.

With the definitions

_n = 1024

_impulse = index(m1(_n), 0, 1)

_ema = lopass(make_ema(5), 1, array(_impulse))

_ema_ema = lopass(make_ema(5), 1, array(_ema)))

_ema_ema_ema = lopass(make_ema(5), 1, array(_ema_ema)))

_ema_long = lopass(make_ema(10), 1, array(_impulse)))

_response_one = fftp(array(_ema))

_response_two = fftp(array(_ema_ema))

_response_three = fftp(array(_ema_ema_ema))

_response_long = fftp(array(_ema_long))

the graph sources

=_n * index(array(_response_one), x + 1, 1)

=_n * index(array(_response_two), x + 1, 1)

=_n * index(array(_response_three), x + 1, 1)

=_n * index(array(_response_long), x + 1, 1)

(where the "+ 1" is to skip the zeroth, constant "harmonic") yield the following amplitude responses for EMA(5) (red), EMA(EMA(5), 5) (green), EMA(EMA(EMA(5), 5), 5) (blue) and EMA(10) (gray):

At the low end of the spectrum (long cycles), the triple EMA is almost indistinguishable from a single EMA twice its length, but it does a much better job suppressing shorter cycles. With the EMA length in the example (5 days) the difference becomes significant somewhere around the 50th harmonic, corresponding to cycle durations of 1024 / 50 » 20 days and shorter. This reflects the intuitively obvious fact that the amplitude response of a filter chain is the pointwise product of the amplitude responses of each filter in the chain.

The price for this improved noise reduction becomes apparent when one plots the the graph sources

=index(array(_response_one), x + 1, 2)

=index(array(_response_two), x + 1, 2)

=index(array(_response_three), x + 1, 2)

=index(array(_response_long), x + 1, 2)

to get the following phase responses:

This shows that triple EMA also means triple phase delay, i.e. triple time lag (the time lag of a filter chain is the sum of the time lags of each filter in the chain).

The trough around the 140th harmonic introduces a phase delay of roughly 0.7 radians (11% of the 2 * PI making up a full cycle) for EMA(5), 1.4 radians for EMA(EMA(5), 5) and almost 2.2 radians for EMA(EMA(EMA(5), 5), 5). In terms of time, the lags are 0.11 * 1024 / 140 » 0.8 days for EMA(5), 1.6 days for EMA(EMA(5), 5) and 2.6 days for EMA(EMA(EMA(5), 5), 5). In comparison, the max delay for EMA(10) is roughly 0.9 radians around the 100th harmonic, or approximately 1 day.

Example

Assuming standard US date format settings,

=trix({{"1/1/1990", 12}, {"1/2/1990", 11}, {"1/3/1990", 12}}, 2)

returns {{32876, 158.333333333333}}. 32876 is the date code for 1/3/1990; 158.33... is the 2 day TRIX value (with default EMA start values) on that date.

See also ema, lopass, make_ema, make_lopass, roc.