-
-
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.
# Describe Request Fixing the way True Range is getting calculated. Fixed #422 # Change Type Bug Fix
- Loading branch information
Showing
6 changed files
with
52 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"singleQuote": true | ||
"singleQuote": true, | ||
"trailingComma": "es5" | ||
} |
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,40 @@ | ||
// Copyright (c) 2022 Onur Cinar. All Rights Reserved. | ||
// https://github.com/cinar/indicatorts | ||
|
||
import { | ||
abs, | ||
checkSameLength, | ||
max, | ||
shiftRightAndFillBy, | ||
subtract, | ||
} from '../../helper/numArray'; | ||
|
||
/** | ||
* True Range (TR). | ||
* | ||
* TR = Max((High - Low), Abs(High - Closing[-1]), Abs(Low - Closing[-1])) | ||
* | ||
* @param period window period. | ||
* @param highs high values. | ||
* @param lows low values. | ||
* @param closings closing values. | ||
* @return tr values. | ||
*/ | ||
export function tr( | ||
period: number, | ||
highs: number[], | ||
lows: number[], | ||
closings: number[] | ||
): number[] { | ||
checkSameLength(highs, lows, closings); | ||
|
||
const previous = shiftRightAndFillBy(1, closings[0], closings); | ||
|
||
const result = max( | ||
subtract(highs, lows), | ||
abs(subtract(highs, previous)), | ||
abs(subtract(lows, previous)) | ||
); | ||
|
||
return result; | ||
} |