UNPKG

rxjs-trading-signals

Version:

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

43 lines 1.9 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.StochasticRSI = void 0; const big_js_1 = __importDefault(require("big.js")); const rxjs_1 = require("rxjs"); const RSI_1 = require("../RSI/RSI"); const WSMA_1 = require("../WSMA/WSMA"); const StochasticRSI = (interval, SmoothingIndicator = WSMA_1.WSMA) => { return (observable) => new rxjs_1.Observable((subscriber) => { let rsiResult = new big_js_1.default(0); const subscription = observable .pipe((0, RSI_1.RSI)(interval, SmoothingIndicator), (0, rxjs_1.tap)(x => (rsiResult = x)), (0, rxjs_1.bufferCount)(interval, 1), (0, rxjs_1.filter)(x => x.length === interval), (0, rxjs_1.concatMap)(periods => { return (0, rxjs_1.zip)((0, rxjs_1.from)(periods).pipe((0, rxjs_1.max)((a, b) => (a.lt(b) ? -1 : 1))), (0, rxjs_1.from)(periods).pipe((0, rxjs_1.min)((a, b) => (a.lt(b) ? -1 : 1)))).pipe((0, rxjs_1.concatMap)(([max, min]) => { const denominator = max.minus(min); if (denominator.eq(0)) { return (0, rxjs_1.of)(new big_js_1.default(100)); } const numerator = rsiResult.minus(min); return (0, rxjs_1.of)(numerator.div(denominator)); })); })) .subscribe({ next(x) { subscriber.next(x); }, error(err) { subscriber.error(err); }, complete() { subscriber.complete(); }, }); return () => { subscription.unsubscribe(); rsiResult = null; }; }); }; exports.StochasticRSI = StochasticRSI; //# sourceMappingURL=StochasticRSI.js.map