UNPKG

@4ex/indicators

Version:

Technical indicators for ohlc charts written in TypeScript

77 lines (76 loc) 2.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MFI = void 0; const fp_1 = require("lodash/fp"); const technicalindicators_1 = require("technicalindicators"); const types_1 = require("../types"); const defaultInput = { period: 14, }; /** * The Money Flow Index (MFI) is a technical oscillator that uses price * and volume data for identifying overbought or oversold signals in an * asset. It can also be used to spot divergences which warn of a trend * change in price. The oscillator moves between 0 and 100. Unlike * conventional oscillators such as the Relative Strength Index (RSI), * the Money Flow Index incorporates both price and volume data, as opposed * to just price. For this reason, some analysts call MFI the volume-weighted * RSI. */ class MFI { /** * @param {OHLC[]} series candles series * @param {number} period period for indicator */ constructor(series, period = defaultInput.period) { // super(); const high = fp_1.map(types_1.OHLCEnum.HIGH)(series); const low = fp_1.map(types_1.OHLCEnum.LOW)(series); const close = fp_1.map(types_1.OHLCEnum.CLOSE)(series); const volume = fp_1.map('volume')(series); this.indicator = new technicalindicators_1.MFI({ high, low, close, volume, period }); } /** * Retrieve MFI values for instance * @return {number[]} values for instance data */ getResults() { return this.indicator.getResult(); } /** * Calculate MFI to next tick * @param {OHLC} candle new candle to add to series * @return {number | undefined} next MFI value or undefined if period is * greater than actual series length */ next(candle) { return this.indicator.nextValue(candle); } /** * Create instance from data * @param {MoneyFlowIndexInput} input input data * @return {MFI} MFI instance */ static generator({ series, period }) { return new MFI(series, period); } /** * Get MFI values from input * @param {MoneyFlowIndexInput} input input data * @return {number[]} MFI values */ static calculate({ series, period, }) { const high = fp_1.map(types_1.OHLCEnum.HIGH)(series); const low = fp_1.map(types_1.OHLCEnum.LOW)(series); const close = fp_1.map(types_1.OHLCEnum.CLOSE)(series); const volume = fp_1.map('volume')(series); return technicalindicators_1.MFI.calculate({ high, low, close, volume, period: period !== null && period !== void 0 ? period : defaultInput.period, }); } } exports.MFI = MFI;