UNPKG

@4ex/indicators

Version:

Technical indicators for ohlc charts written in TypeScript

74 lines (73 loc) 2.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AO = void 0; const fp_1 = require("lodash/fp"); const technicalindicators_1 = require("technicalindicators"); const types_1 = require("../types"); const defaultInput = { fastPeriod: 5, slowPeriod: 34, }; /** * Awesome Oscillator is developed by famous technical analyst and charting * enthusiast Bill Williams. Awesome Oscillator (AO) is an indicator that is * non-limiting oscillator, providing insight into the weakness or the strength * of a stock. The Awesome Oscillator is used to measure market momentum and to * affirm trends or to anticipate possible reversals. It does this by * effectively comparing the recent market momentum, with the general momentum * over a wider frame of reference. */ class AO { /** * @param {OHLC[]} series candles series * @param {number} fastPeriod fast period for indicator * @param {number} slowPeriod slow period for indicator */ constructor(series, fastPeriod = defaultInput.fastPeriod, slowPeriod = defaultInput.slowPeriod) { // super(); const high = fp_1.map(types_1.OHLCEnum.HIGH)(series); const low = fp_1.map(types_1.OHLCEnum.LOW)(series); this.indicator = new technicalindicators_1.AwesomeOscillator({ high, low, fastPeriod, slowPeriod }); } /** * Retrieve AO values for instance * @return {number[]} values for instance data */ getResults() { return this.indicator.getResult(); } /** * Calculate AO to next tick * @param {OHLC} candle new candle to add to series * @return {number | undefined} next AO value or undefined if period is * greater than actual series length */ next(candle) { return this.indicator.nextValue(candle); } /** * Create instance from data * @param {AwesomeOscillatorInput} input input data * @return {AO} AO instance */ static generator({ series, fastPeriod, slowPeriod, }) { return new AO(series, fastPeriod, slowPeriod); } /** * Get AO values from input * @param {AwesomeOscillatorInput} input input data * @return {number[]} AO values */ static calculate(input) { const { series, fastPeriod, slowPeriod } = Object.assign(Object.assign({}, defaultInput), input); const high = fp_1.map(types_1.OHLCEnum.HIGH)(series); const low = fp_1.map(types_1.OHLCEnum.LOW)(series); return technicalindicators_1.AwesomeOscillator.calculate({ high, low, fastPeriod, slowPeriod, }); } } exports.AO = AO;