@4ex/indicators
Version:
Technical indicators for ohlc charts written in TypeScript
66 lines (65 loc) • 2.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ADL = void 0;
const fp_1 = require("lodash/fp");
const technicalindicators_1 = require("technicalindicators");
const types_1 = require("../types");
/**
* The accumulation/distribution line was created by Marc Chaikin
* to determine the flow of money into or out of a security. It should not
* be confused with the advance/decline line. While their initials might be
* the same, these are entirely different indicators, as are their users.
* The advance/decline line provides insight into market movements and the
* accumulation/distribution line is of use to traders seeking to measure
* buy/sell pressure on a security or confirm the strength of a trend.
*/
class ADL {
/**
* @param {OHLC[]} series candle series
*/
constructor(series) {
// 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.ADL({ high, low, close, volume });
}
/**
* Retrieve ADL values for instance
* @return {number[]} values for instance data
*/
getResults() {
return this.indicator.getResult();
}
/**
* Calculate ADL to next tick
* @param {OHLC} candle new candle to add to series
* @return {number | undefined} next adl value or undefined if period is
* greater than actual series length
*/
next(candle) {
return this.indicator.nextValue(candle);
}
/**
* Create instance from data
* @param {AccumulationDistributionLineInput} input input data
* @return {ADL} adl instance
*/
static generator({ series, }) {
return new ADL(series);
}
/**
* Get adl values from input
* @param {AccumulationDistributionLineInput} input input data
* @return {number[]} adl values
*/
static calculate({ series, }) {
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.ADL.calculate({ high, low, close, volume });
}
}
exports.ADL = ADL;