@4ex/indicators
Version:
Technical indicators for ohlc charts written in TypeScript
67 lines (66 loc) • 2.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.OBV = void 0;
const fp_1 = require("lodash/fp");
const technicalindicators_1 = require("technicalindicators");
const types_1 = require("../types");
/**
* On-balance volume (OBV) is a technical trading momentum indicator that
* uses volume flow to predict changes in stock price. Joseph Granville
* first developed the OBV metric in the 1963 book Granville's New Key to
* Stock Market Profits. Granville believed that volume was the key force
* behind markets and designed OBV to project when major moves in the markets
* would occur based on volume changes. In his book, he described the
* predictions generated by OBV as "a spring being wound tightly." He believed
* that when volume increases sharply without a significant change in the
* stock's price, the price will eventually jump upward or fall downward.
*/
class OBV {
/**
* @param {OHLC[]} series candles series
*/
constructor(series) {
// super();
const volume = fp_1.map('volume')(series);
const close = fp_1.map(types_1.OHLCEnum.CLOSE)(series);
this.indicator = new technicalindicators_1.OBV({ close, volume });
}
/**
* Retrieve OBV values for instance
* @return {number[]} values for instance data
*/
getResults() {
return this.indicator.getResult();
}
/**
* Calculate OBV to next tick
* @param {OHLC} candle new candle to add to series
* @return {number | undefined} next OBV value or undefined if period is
* greater than actual series length
*/
next(candle) {
return this.indicator.nextValue(candle);
}
/**
* Create instance from data
* @param {OnBalanceVolumeInput} input input data
* @return {OBV} OBV instance
*/
static generator({ series }) {
return new OBV(series);
}
/**
* Get OBV values from input
* @param {OnBalanceVolumeInput} input input data
* @return {number[]} OBV values
*/
static calculate({ series, }) {
const volume = fp_1.map('volume')(series);
const close = fp_1.map(types_1.OHLCEnum.CLOSE)(series);
return technicalindicators_1.OBV.calculate({
close,
volume,
});
}
}
exports.OBV = OBV;