rxjs-trading-signals
Version:
The user - defined operator helps users quickly output index values. base trading-signals library
40 lines • 1.39 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DMA = void 0;
const big_js_1 = __importDefault(require("big.js"));
const rxjs_1 = require("rxjs");
const SMA_1 = require("../SMA/SMA");
const DMA = (short, long, Indicator = SMA_1.SMA) => {
return (observable) => new rxjs_1.Observable((subscriber) => {
if (short > long) {
[short, long] = [long, short];
}
const source$ = observable.pipe((0, rxjs_1.share)());
const subscription = (0, rxjs_1.zip)(source$.pipe(Indicator(short), (0, rxjs_1.skip)(long - short)), source$.pipe(Indicator(long)))
.pipe((0, rxjs_1.concatMap)(([short, long]) => {
return (0, rxjs_1.of)({
long: new big_js_1.default(long),
short: new big_js_1.default(short),
});
}))
.subscribe({
next(x) {
subscriber.next(x);
},
error(err) {
subscriber.error(err);
},
complete() {
subscriber.complete();
},
});
return () => {
subscription.unsubscribe();
};
});
};
exports.DMA = DMA;
//# sourceMappingURL=DMA.js.map