'use strict'; import _ from 'underscore'; import NumberUtil from '../utils/number.js'; import ValidateMixin from '../mixin/validate.js'; import SetOptionsMixin from '../mixin/set-options.js'; import HandleGeneratorMixin from '../mixin/handle-generator.js'; import EMA from './exponential-moving-average.js'; /** * @param {object} [options] * @param {number} [optons.periods=15] * @param {number} [options.startIndex] * @param {number} [options.endIndex}] * @param {boolean} [options.sliceOffset=false] * @param {boolean} [options.lazyEvaluation=true] * @param {number} [option.maxTickDuration=10] */ function TRIX(options = {}) { if (!new.target) throw new Error('ERROR: TRIX() must be called with new'); this._options = { periods: 15, startIndex: null, endIndex: null, sliceOffset: false, lazyEvaluation: true, maxTickDuration: 10, } let m = [SetOptionsMixin, ValidateMixin, HandleGeneratorMixin]; Object.assign(this, ...m); this.setOptions(options); this._collection = []; } TRIX.prototype = { setValues(values) { if (!Array.isArray(values)) { throw new Error('ERROR: values param is not an array'); } this._collection = values; }, calculate() { this._validate(this._collection, this._options); return this._handleGenerator(this._compute()); }, _compute: function* () { let results = []; let { periods, startIndex, endIndex, sliceOffset, lazyEvaluation } = this._options; let singleEMA = new EMA({ periods, lazyEvaluation: false }); singleEMA.setValues(this._collection); let singleEmaResults = singleEMA.calculate(); console.log(singleEmaResults); return results; }, } export default TRIX;