UNPKG

rxjs-trading-signals

Version:

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

36 lines 1.71 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CCI = void 0; const big_js_1 = __importDefault(require("big.js")); const rxjs_1 = require("rxjs"); const SMA_1 = require("../SMA/SMA"); const CCI = (interval) => { return (observable) => new rxjs_1.Observable((subscriber) => { const source$ = observable.pipe((0, rxjs_1.concatMap)(({ high, low, close }) => { return (0, rxjs_1.of)(new big_js_1.default(high).plus(low).plus(close).div(3)); }), (0, rxjs_1.share)()); const subscription = (0, rxjs_1.zip)(source$.pipe((0, SMA_1.SMA)(interval)), source$.pipe((0, rxjs_1.bufferCount)(interval, 1))) .pipe((0, rxjs_1.concatMap)(([mean, typicalPrices]) => { return (0, rxjs_1.zip)((0, rxjs_1.of)(typicalPrices[typicalPrices.length - 1].minus(mean)), (0, rxjs_1.from)(typicalPrices).pipe((0, rxjs_1.scan)((curr, next) => curr.plus(next.minus(mean).abs()), new big_js_1.default(0)), (0, rxjs_1.last)(), (0, rxjs_1.map)(x => x.div(interval)))).pipe((0, rxjs_1.map)(([numerator, meanDeviation]) => numerator.div(new big_js_1.default(0.015).mul(meanDeviation)))); })) .subscribe({ next(x) { subscriber.next(x); }, error(err) { subscriber.error(err); }, complete() { subscriber.complete(); }, }); return () => { subscription.unsubscribe(); }; }); }; exports.CCI = CCI; //# sourceMappingURL=CCI.js.map