UNPKG

@thuantan2060/technicalindicators

Version:
88 lines (77 loc) 3.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DEFAULT_BULLISH_HAMMER_CONFIG = void 0; exports.bullishhammerstick = bullishhammerstick; 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 BullishHammerStick pattern. * Includes thresholds for shadow and body analysis. */ /** * Default configuration for BullishHammerStick pattern. */ const DEFAULT_BULLISH_HAMMER_CONFIG = exports.DEFAULT_BULLISH_HAMMER_CONFIG = { ..._CandlestickFinder.DEFAULT_CANDLESTICK_CONFIG, shadowSizeThresholdPercent: 0.001, minBodyComparisonPercent: 0.0001 }; class BullishHammerStick extends _CandlestickFinder.default { shadowSizeThresholdPercent; minBodyComparisonPercent; constructor(config) { const finalConfig = { ...DEFAULT_BULLISH_HAMMER_CONFIG, ...config }; super(finalConfig); this.name = 'BullishHammerStick'; this.requiredCount = 1; // Apply configuration with defaults this.shadowSizeThresholdPercent = finalConfig.shadowSizeThresholdPercent; this.minBodyComparisonPercent = finalConfig.minBodyComparisonPercent; } 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 a bullish candle (green candle) or doji-like let isBullishHammer = daysClose >= daysOpen; // The close should be approximately equal to the high (small upper shadow) isBullishHammer = isBullishHammer && this.approximateEqual(daysClose, daysHigh); // Calculate sizes let bodySize = Math.abs(daysClose - daysOpen); let lowerShadow = Math.min(daysOpen, daysClose) - daysLow; let totalRange = daysHigh - daysLow; // Ensure we have a meaningful range to work with if (totalRange <= 0) { return false; } // Handle very small bodies (doji-like hammers) // Use direct threshold calculation instead of utility function let minBodyForComparison = Math.max(bodySize, totalRange * this.minBodyComparisonPercent); // The lower shadow should be at least twice the effective body size isBullishHammer = isBullishHammer && lowerShadow >= 2 * minBodyForComparison; // Ensure there's a significant lower shadow relative to the total range // Use direct threshold calculations instead of utility functions let minShadowSize = Math.max(totalRange * this.shadowSizeThresholdPercent * 300, // Replaces: getShadowSizeThreshold(totalRange) * 300 minBodyForComparison * 2 // At least twice the effective body size ); isBullishHammer = isBullishHammer && lowerShadow >= minShadowSize; return isBullishHammer; } } exports.default = BullishHammerStick; function bullishhammerstick(data, options = DEFAULT_BULLISH_HAMMER_CONFIG) { return new BullishHammerStick(options).hasPattern(data); } //# sourceMappingURL=BullishHammerStick.js.map