UNPKG

rxjs-trading-signals

Version:

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

71 lines 3.06 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DX = void 0; const big_js_1 = __importDefault(require("big.js")); const rxjs_1 = require("rxjs"); const WSMA_1 = require("../WSMA/WSMA"); const ATR_1 = require("../ATR/ATR"); const DX = (interval, SmoothingIndicator = WSMA_1.WSMA) => { return (observable) => new rxjs_1.Observable((subscriber) => { let prevCandle; const source$ = observable.pipe((0, rxjs_1.concatMap)((candle, i) => { if (i === 0) { prevCandle = candle; return (0, rxjs_1.of)({ candle, pdm: 0, mdm: 0, }); } const currentHigh = new big_js_1.default(candle.high); const previousHigh = new big_js_1.default(prevCandle.high); const currentLow = new big_js_1.default(candle.low); const previousLow = new big_js_1.default(prevCandle.low); const higherHigh = currentHigh.minus(previousHigh); const lowerLow = previousLow.minus(currentLow); const noHigherHighs = higherHigh.lt(0); const lowsRiseFaster = higherHigh.lt(lowerLow); const pdm = noHigherHighs || lowsRiseFaster ? new big_js_1.default(0) : higherHigh; const noLowerLows = lowerLow.lt(0); const highsRiseFaster = lowerLow.lt(higherHigh); const mdm = noLowerLows || highsRiseFaster ? new big_js_1.default(0) : lowerLow; prevCandle = candle; return (0, rxjs_1.of)({ candle, pdm, mdm, }); }), (0, rxjs_1.share)()); const subscription = (0, rxjs_1.zip)(source$.pipe((0, rxjs_1.map)(({ candle }) => candle), (0, ATR_1.ATR)(interval, SmoothingIndicator)), source$.pipe((0, rxjs_1.map)(({ mdm }) => mdm), SmoothingIndicator(interval)), source$.pipe((0, rxjs_1.map)(({ pdm }) => pdm), SmoothingIndicator(interval))) .pipe((0, rxjs_1.concatMap)(([atr, movesDown, movesUp]) => { const pdi = new big_js_1.default(movesUp).div(atr); const mdi = new big_js_1.default(movesDown).div(atr); const dmDiff = pdi.minus(mdi).abs(); const dmSum = pdi.plus(mdi); if (dmSum.eq(0)) { return (0, rxjs_1.of)(new big_js_1.default(0)); } return (0, rxjs_1.of)(dmDiff.div(dmSum).times(100)); })) .subscribe({ next(x) { subscriber.next(x); }, error(err) { subscriber.error(err); }, complete() { subscriber.complete(); }, }); return () => { subscription.unsubscribe(); prevCandle = null; }; }); }; exports.DX = DX; //# sourceMappingURL=DX.js.map