UNPKG

@4ex/indicators

Version:

Technical indicators for ohlc charts written in TypeScript

90 lines (89 loc) 3.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Ichimoku = void 0; const fp_1 = require("lodash/fp"); const technicalindicators_1 = require("technicalindicators"); const types_1 = require("../types"); const defaultInput = { conversionPeriod: 9, basePeriod: 26, spanPeriod: 52, displacement: 26, }; /** * The Ichimoku Cloud is a collection of technical indicators that show support * and resistance levels, as well as momentum and trend direction. It does this * by taking multiple averages and plotting them on the chart. It also uses * these figures to compute a "cloud" which attempts to forecast where the * price may find support or resistance in the future. The Ichimoku cloud was * developed by Goichi Hosoda, a Japanese journalist, and published in the late * 1960s. It provides more data points than the standard candlestick chart. * While it seems complicated at first glance, those familiar with how to read * the charts often find it easy to understand with well-defined trading * signals. */ class Ichimoku { /** * @param {OHLC[]} series candles series * @param {number} conversionPeriod * @param {number} basePeriod * @param {number} spanPeriod * @param {number} displacement */ constructor(series, conversionPeriod = defaultInput.conversionPeriod, basePeriod = defaultInput.basePeriod, spanPeriod = defaultInput.spanPeriod, displacement = defaultInput.displacement) { // super(); const high = fp_1.map(types_1.OHLCEnum.HIGH)(series); const low = fp_1.map(types_1.OHLCEnum.LOW)(series); this.indicator = new technicalindicators_1.IchimokuCloud({ high, low, conversionPeriod, basePeriod, spanPeriod, displacement, }); } /** * Retrieve Ichimoku values for instance * @return {IchimokuOutput[]} values for instance data */ getResults() { return this.indicator.getResult(); } /** * Calculate Ichimoku to next tick * @param {OHLC} candle new candle to add to series * @return {IchimokuOutput | undefined} next Ichimoku value or undefined * if period is greater than actual series length */ next(candle) { return this.indicator.nextValue(candle); } /** * Create instance from data * @param {IchimokuInput} input input data * @return {Ichimoku} Ichimoku instance */ static generator({ series, conversionPeriod, basePeriod, spanPeriod, displacement, }) { return new Ichimoku(series, conversionPeriod, basePeriod, spanPeriod, displacement); } /** * Get Ichimoku values from input * @param {IchimokuInput} input input data * @return {IchimokuOutput[]} Ichimoku values */ static calculate(input) { const { series, conversionPeriod, basePeriod, spanPeriod, displacement, } = Object.assign(Object.assign({}, defaultInput), input); const high = fp_1.map(types_1.OHLCEnum.HIGH)(series); const low = fp_1.map(types_1.OHLCEnum.LOW)(series); return technicalindicators_1.IchimokuCloud.calculate({ high, low, conversionPeriod, basePeriod, spanPeriod, displacement, }); } } exports.Ichimoku = Ichimoku;