UNPKG

@thuantan2060/technicalindicators

Version:
66 lines (59 loc) 2.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DEFAULT_BULLISH_SPINNING_TOP_CONFIG = void 0; exports.bullishspinningtop = bullishspinningtop; exports.default = void 0; 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 BullishSpinningTop pattern. */ /** * Default configuration for BullishSpinningTop pattern. */ const DEFAULT_BULLISH_SPINNING_TOP_CONFIG = exports.DEFAULT_BULLISH_SPINNING_TOP_CONFIG = { ..._CandlestickFinder.DEFAULT_CANDLESTICK_CONFIG, maxBodyLength: 1 // Body should be <= 1 price units to be considered "small" }; class BullishSpinningTop extends _CandlestickFinder.default { /** Maximum body length for small body detection */ maxBodyLength; constructor(config) { const finalConfig = { ...DEFAULT_BULLISH_SPINNING_TOP_CONFIG, ...config }; super(finalConfig); this.name = 'BullishSpinningTop'; this.requiredCount = 1; this.maxBodyLength = finalConfig.maxBodyLength; } logic(data) { let daysOpen = data.open[0]; let daysClose = data.close[0]; let daysHigh = data.high[0]; let daysLow = data.low[0]; // Validate OHLC data integrity first if (!this.validateOHLC(daysOpen, daysHigh, daysLow, daysClose)) { return false; } // Must be bullish (close > open) let isBullish = daysClose > daysOpen; let bodyLength = Math.abs(daysClose - daysOpen); // For bullish candles: top of body is close, bottom is open let upperShadowLength = Math.abs(daysHigh - daysClose); let lowerShadowLength = Math.abs(daysOpen - daysLow); // Check if body is small based on fixed length threshold let hasSmallBody = bodyLength <= this.maxBodyLength; // Spinning top: bullish + small body + body length < both shadow lengths let isBullishSpinningTop = isBullish && hasSmallBody && bodyLength < upperShadowLength && bodyLength < lowerShadowLength; return isBullishSpinningTop; } } exports.default = BullishSpinningTop; function bullishspinningtop(data, config = DEFAULT_BULLISH_SPINNING_TOP_CONFIG) { return new BullishSpinningTop(config).hasPattern(data); } //# sourceMappingURL=BullishSpinningTop.js.map