@4ex/indicators
Version:
Technical indicators for ohlc charts written in TypeScript
63 lines (62 loc) • 2.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.VWAP = void 0;
const fp_1 = require("lodash/fp");
const technicalindicators_1 = require("technicalindicators");
const types_1 = require("../types");
/**
* The volume weighted average price (VWAP) is a trading benchmark used by
* traders that gives the average price a security has traded at throughout
* the day, based on both volume and price. It is important because it provides
* traders with insight into both the trend and value of a security.
*/
class VWAP {
/**
* @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.VWAP({ high, low, close, volume });
}
/**
* Retrieve VWAP values for instance
* @return {number[]} values for instance data
*/
getResults() {
return this.indicator.getResult();
}
/**
* Calculate VWAP 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 {VolumeWeightedAveragePriceInput} input input data
* @return {VWAP} adl instance
*/
static generator({ series, }) {
return new VWAP(series);
}
/**
* Get adl values from input
* @param {VolumeWeightedAveragePriceInput} 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.VWAP.calculate({ high, low, close, volume });
}
}
exports.VWAP = VWAP;