UNPKG

rxjs-trading-signals

Version:

The user - defined operator helps users quickly output index values. base trading-signals library

47 lines 2.28 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AccelerationBands = void 0; const big_js_1 = __importDefault(require("big.js")); const rxjs_1 = require("rxjs"); const SMA_1 = require("../SMA/SMA"); const AccelerationBands = (interval, width, SmoothingIndicator = SMA_1.SMA) => { return (observable) => new rxjs_1.Observable((subscriber) => { const source$ = observable.pipe((0, rxjs_1.concatMap)(({ high, low, close }) => { const highPlusLow = new big_js_1.default(high).plus(low); const coefficient = highPlusLow.eq(0) ? new big_js_1.default(0) : new big_js_1.default(high).minus(low).div(highPlusLow).times(width); const lowerBand = new big_js_1.default(low).times(new big_js_1.default(1).minus(coefficient)); const middleBand = new big_js_1.default(close); const upperBand = new big_js_1.default(high).times(new big_js_1.default(1).plus(coefficient)); return (0, rxjs_1.of)({ lowerBand, middleBand, upperBand, }); }), (0, rxjs_1.share)()); const subscription = (0, rxjs_1.zip)(source$.pipe((0, rxjs_1.map)(({ lowerBand }) => lowerBand), SmoothingIndicator(interval)), source$.pipe((0, rxjs_1.map)(({ middleBand }) => middleBand), SmoothingIndicator(interval)), source$.pipe((0, rxjs_1.map)(({ upperBand }) => upperBand), SmoothingIndicator(interval))) .pipe((0, rxjs_1.map)(([lowerBand, middleBand, upperBand]) => ({ lower: new big_js_1.default(lowerBand), middle: new big_js_1.default(middleBand), upper: new big_js_1.default(upperBand), }))) .subscribe({ next(x) { subscriber.next(x); }, error(err) { subscriber.error(err); }, complete() { subscriber.complete(); }, }); return () => { subscription.unsubscribe(); }; }); }; exports.AccelerationBands = AccelerationBands; //# sourceMappingURL=AccelerationBands.js.map