forked from cinar/indicatorts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qstick.ts
40 lines (35 loc) · 929 Bytes
/
qstick.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (c) 2022 Onur Cinar. All Rights Reserved.
// https://github.com/cinar/indicatorts
import { subtract } from '../../helper/numArray';
import { sma } from './simpleMovingAverage';
/**
* Optional configuration of Qstick parameters.
*/
export interface QstickConfig {
period?: number;
}
/**
* The default configuration of Qstick.
*/
export const QstickDefaultConfig: Required<QstickConfig> = {
period: 14,
};
/**
* The Qstick function calculates the ratio of recent up and down bars.
*
* QS = Sma(Closing - Opening)
*
* @param openings openinig values.
* @param closings closing values.
* @param config configuration.
* @return qstick values.
*/
export function qstick(
openings: number[],
closings: number[],
config: QstickConfig = {}
): number[] {
const { period } = { ...QstickDefaultConfig, ...config };
const result = sma(subtract(closings, openings), { period });
return result;
}