-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Triple Exponential Average (TRIX) is added. (#30)
- Loading branch information
Showing
8 changed files
with
109 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) 2022 Onur Cinar. All Rights Reserved. | ||
// https://github.com/cinar/indicatorts | ||
|
||
import { roundDigitsAll } from '../../helper/numArray'; | ||
import { trix } from './trix'; | ||
|
||
describe('Triple Exponential Average (TRIX)', () => { | ||
it('should be able to compute TRIX', () => { | ||
const values = [2, 4, 6, 8, 12, 14, 16, 18, 20]; | ||
const period = 4; | ||
const expected = [0, 0.06, 0.17, 0.26, 0.33, 0.33, 0.3, 0.25, 0.21]; | ||
|
||
const actual = trix(period, values); | ||
expect(roundDigitsAll(2, actual)).toStrictEqual(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) 2022 Onur Cinar. All Rights Reserved. | ||
// https://github.com/cinar/indicatorts | ||
|
||
import { divide, shiftRightAndFillBy, substract } from '../../helper/numArray'; | ||
import { ema } from './ema'; | ||
|
||
/** | ||
* Triple Exponential Average (TRIX) indicator is an oscillator used to | ||
* identify oversold and overbought markets, and it can also be used | ||
* as a momentum indicator. Like many oscillators, TRIX oscillates | ||
* around a zero line. | ||
* | ||
* EMA1 = EMA(period, values) | ||
* EMA2 = EMA(period, EMA1) | ||
* EMA3 = EMA(period, EMA2) | ||
* TRIX = (EMA3 - Previous EMA3) / Previous EMA3 | ||
* | ||
* @param period window period. | ||
* @param values values array. | ||
* @returns trix values. | ||
*/ | ||
export function trix(period: number, values: number[]): number[] { | ||
const ema1 = ema(period, values); | ||
const ema2 = ema(period, ema1); | ||
const ema3 = ema(period, ema2); | ||
const previous = shiftRightAndFillBy(1, ema3[0], ema3); | ||
const trix = divide(substract(ema3, previous), previous); | ||
return trix; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters