@4ex/indicators
Version:
Technical indicators for ohlc charts written in TypeScript
72 lines (71 loc) • 2.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FI = void 0;
const fp_1 = require("lodash/fp");
const technicalindicators_1 = require("technicalindicators");
const types_1 = require("../types");
const defaultInput = {
period: 13,
};
/**
* The force index is a technical indicator that measures the amount of
* power used to move the price of an asset. The term and its formula were
* developed by psychologist and trader Alexander Elder and published in his
* 1993 book Trading for a Living. The force index uses price and volume to
* determine the amount of strength behind a price move. The index is an
* oscillator, fluctuating between positive and negative territory. It is
* unbounded meaning the index can go up or down indefinitely. The force index
* is used for trend and breakout confirmation, as well as spotting potential
* turning points by looking for divergences.
*/
class FI {
/**
* @param {OHLC[]} series candles series
* @param {number} period period for indicator
*/
constructor(series, period = defaultInput.period) {
// super();
const volume = fp_1.map('volume')(series);
const close = fp_1.map(types_1.OHLCEnum.CLOSE)(series);
this.indicator = new technicalindicators_1.ForceIndex({ volume, close, period });
}
/**
* Retrieve FI values for instance
* @return {number[]} values for instance data
*/
getResults() {
return this.indicator.getResult();
}
/**
* Calculate FI to next tick
* @param {OHLC} candle new candle to add to series
* @return {number | undefined} next FI value or undefined if period is
* greater than actual series length
*/
next(candle) {
return this.indicator.nextValue(candle);
}
/**
* Create instance from data
* @param {ForceIndexInput} input input data
* @return {FI} FI instance
*/
static generator({ series, period }) {
return new FI(series, period);
}
/**
* Get FI values from input
* @param {ForceIndexInput} input input data
* @return {number[]} FI values
*/
static calculate({ series, period, }) {
const volume = fp_1.map('volume')(series);
const close = fp_1.map(types_1.OHLCEnum.CLOSE)(series);
return technicalindicators_1.ForceIndex.calculate({
volume,
close,
period: period !== null && period !== void 0 ? period : defaultInput.period,
});
}
}
exports.FI = FI;