UNPKG

@thuantan2060/technicalindicators

Version:
67 lines (60 loc) 2.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DEFAULT_BEARISH_SPINNING_TOP_CONFIG = void 0; exports.bearishspinningtop = bearishspinningtop; 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 BearishSpinningTop pattern. */ /** * Default configuration for BearishSpinningTop pattern. */ const DEFAULT_BEARISH_SPINNING_TOP_CONFIG = exports.DEFAULT_BEARISH_SPINNING_TOP_CONFIG = { ..._CandlestickFinder.DEFAULT_CANDLESTICK_CONFIG, maxBodyLength: 1 // Body should be <= 1 price units to be considered "small" }; class BearishSpinningTop extends _CandlestickFinder.default { /** Maximum body length for small body detection */ maxBodyLength; constructor(config) { const finalConfig = { ...DEFAULT_BEARISH_SPINNING_TOP_CONFIG, ...config }; super(finalConfig); this.name = 'BearishSpinningTop'; 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]; // Basic OHLC validation if (!this.validateOHLC(daysOpen, daysHigh, daysLow, daysClose)) { return false; } // Must be bearish (close < open) let isBearish = daysClose < daysOpen; let bodyLength = Math.abs(daysClose - daysOpen); let totalRange = daysHigh - daysLow; // For bearish candles: top of body is open, bottom is close let upperShadowLength = Math.abs(daysHigh - daysOpen); let lowerShadowLength = Math.abs(daysClose - daysLow); // Check if body is small based on fixed length threshold let hasSmallBody = bodyLength <= this.maxBodyLength; // Spinning top: bearish + small body + body length < both shadow lengths let isBearishSpinningTop = isBearish && hasSmallBody && bodyLength < upperShadowLength && bodyLength < lowerShadowLength; return isBearishSpinningTop; } } exports.default = BearishSpinningTop; function bearishspinningtop(data, config = DEFAULT_BEARISH_SPINNING_TOP_CONFIG) { return new BearishSpinningTop(config).hasPattern(data); } //# sourceMappingURL=BearishSpinningTop.js.map