UNPKG

@thuantan2060/technicalindicators

Version:
79 lines (71 loc) 3.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.DEFAULT_DRAGONFLY_DOJI_CONFIG = void 0; exports.dragonflydoji = dragonflydoji; var _CandlestickFinder = _interopRequireWildcard(require("./CandlestickFinder")); function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } /** * Configuration interface for DragonFlyDoji pattern. * Only requires scale parameter since this pattern uses approximateEqual for body tolerance. */ /** * Default configuration for DragonFlyDoji pattern. */ const DEFAULT_DRAGONFLY_DOJI_CONFIG = exports.DEFAULT_DRAGONFLY_DOJI_CONFIG = { ..._CandlestickFinder.DEFAULT_CANDLESTICK_CONFIG }; class DragonFlyDoji extends _CandlestickFinder.default { constructor(config) { const finalConfig = { ...DEFAULT_DRAGONFLY_DOJI_CONFIG, ...config }; super(finalConfig); this.requiredCount = 1; this.name = 'DragonFlyDoji'; } logic(data) { let daysOpen = data.open[0]; let daysClose = data.close[0]; let daysHigh = data.high[0]; let daysLow = data.low[0]; // Basic validation - check for NaN or infinite values and basic OHLC constraints if (!isFinite(daysOpen) || !isFinite(daysHigh) || !isFinite(daysLow) || !isFinite(daysClose)) { return false; } // Check basic OHLC constraints (works correctly for both positive and negative prices) if (daysHigh < Math.max(daysOpen, daysClose) || daysLow > Math.min(daysOpen, daysClose)) { return false; } // DragonFly Doji: Open ≈ Close, and both are near the High, with a long lower shadow // Note: approximateEqual now uses fixed thresholds instead of scale let isOpenEqualsClose = this.approximateEqual(daysOpen, daysClose); // Calculate shadows and body let bodySize = Math.abs(daysClose - daysOpen); let lowerShadow = Math.min(daysOpen, daysClose) - daysLow; let upperShadow = daysHigh - Math.max(daysOpen, daysClose); let totalRange = daysHigh - daysLow; // For DragonFly Doji, the open/close should be near the high // Check if both open and close are individually close to high (more flexible approach) let isOpenNearHigh = this.approximateEqual(daysOpen, daysHigh); let isCloseNearHigh = this.approximateEqual(daysClose, daysHigh); let isBodyNearHigh = isOpenNearHigh || isCloseNearHigh; // DragonFly Doji criteria: // 1. Open ≈ Close (small body) // 2. Open or Close near the High (body at the top) // 3. Long lower shadow (at least 2x the body size or 60% of total range) // 4. Minimal upper shadow (less than 10% of total range) let hasSmallBody = isOpenEqualsClose; let hasBodyAtTop = isBodyNearHigh; let hasLongLowerShadow = lowerShadow >= Math.max(bodySize * 2, totalRange * 0.6); let hasMinimalUpperShadow = upperShadow <= totalRange * 0.1; return hasSmallBody && hasBodyAtTop && hasLongLowerShadow && hasMinimalUpperShadow && totalRange > 0; } } exports.default = DragonFlyDoji; function dragonflydoji(data, config = DEFAULT_DRAGONFLY_DOJI_CONFIG) { return new DragonFlyDoji(config).hasPattern(data); } //# sourceMappingURL=DragonFlyDoji.js.map