-
-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathvolumePriceTrend.ts
More file actions
34 lines (30 loc) · 925 Bytes
/
Copy pathvolumePriceTrend.ts
File metadata and controls
34 lines (30 loc) · 925 Bytes
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
// Copyright (c) 2022 Onur Cinar. All Rights Reserved.
// https://github.com/cinar/indicatorts
import {
divide,
multiply,
shiftRightAndFillBy,
subtract,
} from '../../helper/numArray';
import { msum } from '../trend/movingSum';
/**
* The Volume Price Trend (VPT) provides a correlation between the volume and
* the price.
*
* VPT = Previous VPT + (Volume * (Current Closing - Previous Closing) / Previous Closing)
*
* @param closings closing values.
* @param volumes volume values.
* @returns volume price trend values.
*/
export function vpt(closings: number[], volumes: number[]): number[] {
const previousClosings = shiftRightAndFillBy(1, closings[0], closings);
const vpt = multiply(
volumes,
divide(subtract(closings, previousClosings), previousClosings)
);
const result = msum(vpt, { period: vpt.length });
return result;
}
// Export full name
export { vpt as volumePriceTrend };