-
-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathtypicalPriceStrategy.ts
More file actions
34 lines (28 loc) · 884 Bytes
/
Copy pathtypicalPriceStrategy.ts
File metadata and controls
34 lines (28 loc) · 884 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 { Asset } from '../asset';
import { Action } from '../action';
import { typprice } from '../../indicator/trend/typicalPrice';
/**
* Typical price strategy function.
*
* @param asset asset object.
* @return strategy actions.
*/
export function typpriceStrategy(asset: Asset): Action[] {
const result = typprice(asset.highs, asset.lows, asset.closings);
const actions = new Array<Action>(result.length);
actions[0] = Action.HOLD;
for (let i = 1; i < actions.length; i++) {
if (result[i] > result[i - 1]) {
actions[i] = Action.BUY;
} else if (result[i] < result[i - 1]) {
actions[i] = Action.SELL;
} else {
actions[i] = Action.HOLD;
}
}
return actions;
}
// Export full name
export { typpriceStrategy as typicalPriceStrategy };