UNPKG

rxjs-trading-signals

Version:

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

46 lines 1.72 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.WSMA = void 0; const big_js_1 = __importDefault(require("big.js")); const rxjs_1 = require("rxjs"); const SMA_1 = require("../SMA/SMA"); const isZero_1 = require("../utils/isZero"); const WSMA = (interval) => { return (observable) => new rxjs_1.Observable((subscriber) => { let result = new big_js_1.default(0); let curr = new big_js_1.default(0); const smoothingFactor = new big_js_1.default(1).div(interval); const subscription = observable .pipe((0, rxjs_1.tap)(price => (curr = price)), (0, SMA_1.SMA)(interval), (0, rxjs_1.concatMap)(sma => { if (!(0, isZero_1.isZero)(result)) { const smoothed = new big_js_1.default(curr).minus(result).times(smoothingFactor); result = smoothed.plus(result); } else if ((0, isZero_1.isZero)(result) && sma) { result = new big_js_1.default(sma); } return (0, rxjs_1.of)(result).pipe((0, rxjs_1.filter)(x => !(0, isZero_1.isZero)(x))); })) .subscribe({ next(x) { subscriber.next(x); }, error(err) { subscriber.error(err); }, complete() { subscriber.complete(); }, }); return () => { subscription.unsubscribe(); result = null; curr = null; }; }); }; exports.WSMA = WSMA; //# sourceMappingURL=WSMA.js.map