forked from cinar/indicatorts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
awesomeOscillator.ts
48 lines (43 loc) · 1.1 KB
/
awesomeOscillator.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
41
42
43
44
45
46
47
48
// Copyright (c) 2022 Onur Cinar. All Rights Reserved.
// https://github.com/cinar/indicatorts
import { add, divideBy, subtract } from '../../helper/numArray';
import { sma } from '../trend/simpleMovingAverage';
/**
* Optional configuration of AO parameters.
*/
export interface AOConfig {
fast?: number;
slow?: number;
}
/**
* The default configuration of AO.
*/
export const AODefaultConfig: Required<AOConfig> = {
fast: 5,
slow: 34,
};
/**
* Awesome Oscillator (AO).
*
* Median Price = ((Low + High) / 2).
* AO = 5-Period SMA - 34-Period SMA.
*
* @param highs high values.
* @param lows low values.
* @param config configuration.
* @return awesome oscillator.
*/
export function ao(
highs: number[],
lows: number[],
config: AOConfig = {}
): number[] {
const { fast, slow } = { ...AODefaultConfig, ...config };
const medianPrice = divideBy(2, add(lows, highs));
const smaFast = sma(medianPrice, { period: fast });
const smaSlow = sma(medianPrice, { period: slow });
const result = subtract(smaFast, smaSlow);
return result;
}
// Export full name
export { ao as awesomeOscillator };