UNPKG

rxjs-trading-signals

Version:

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

34 lines 1.41 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.MAD = void 0; const big_js_1 = __importDefault(require("big.js")); const rxjs_1 = require("rxjs"); const SMA_1 = require("../SMA/SMA"); const MAD = (interval) => { return (observable) => new rxjs_1.Observable((subscriber) => { const source$ = observable.pipe((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), (0, rxjs_1.filter)(x => x.length === interval))) .pipe((0, rxjs_1.concatMap)(([mean, prices]) => { return (0, rxjs_1.from)(prices).pipe((0, rxjs_1.scan)((curr, next) => curr.plus(new big_js_1.default(next).minus(mean).abs()), new big_js_1.default(0)), (0, rxjs_1.last)(), (0, rxjs_1.map)(x => x.div(prices.length || 1))); })) .subscribe({ next(x) { subscriber.next(x); }, error(err) { subscriber.error(err); }, complete() { subscriber.complete(); }, }); return () => { subscription.unsubscribe(); }; }); }; exports.MAD = MAD; //# sourceMappingURL=MAD.js.map