@thuantan2060/technicalindicators
Version:
Techincal Indicators written in javascript
91 lines (78 loc) • 3.97 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.DEFAULT_BEARISH_HAMMER_STICK_CONFIG = void 0;
exports.bearishhammerstick = bearishhammerstick;
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 BearishHammerStick pattern.
* Extends base config with hammer-specific threshold properties.
*/
/**
* Default configuration for BearishHammerStick pattern.
*/
const DEFAULT_BEARISH_HAMMER_STICK_CONFIG = exports.DEFAULT_BEARISH_HAMMER_STICK_CONFIG = {
..._CandlestickFinder.DEFAULT_CANDLESTICK_CONFIG,
shadowSizeThresholdPercent: 0.3,
minBodyComparisonPercent: 0.0001
};
class BearishHammerStick extends _CandlestickFinder.default {
shadowSizeThresholdPercent;
minBodyComparisonPercent;
constructor(config) {
const finalConfig = {
...DEFAULT_BEARISH_HAMMER_STICK_CONFIG,
...config
};
super(finalConfig);
this.name = 'BearishHammerStick';
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 bearish candle (red candle)
let isBearishHammer = daysOpen > daysClose;
// The open should be approximately equal to the high (small upper shadow)
isBearishHammer = isBearishHammer && this.approximateEqual(daysOpen, daysHigh);
// Calculate sizes
let bodySize = daysOpen - daysClose;
let lowerShadow = 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)
// For shadow comparison, use actual body size but ensure a minimum threshold for very small bodies
let minBodyThreshold = totalRange * this.minBodyComparisonPercent;
let effectiveBodyForShadowComparison = Math.max(bodySize, minBodyThreshold);
// The lower shadow should be at least 1.5 times the effective body size (more lenient than 2x)
let shadowVsBodyCheck = lowerShadow >= 1.5 * effectiveBodyForShadowComparison;
// Ensure there's a significant lower shadow relative to the total range
// Use OR logic: either percentage-based OR body-based threshold should be satisfied
let percentageBasedThreshold = totalRange * this.shadowSizeThresholdPercent;
let bodyBasedThreshold = effectiveBodyForShadowComparison * 1.5; // Updated to match the check above
let shadowVsRangeCheck = lowerShadow >= percentageBasedThreshold || lowerShadow >= bodyBasedThreshold;
// Both checks should pass
isBearishHammer = isBearishHammer && shadowVsBodyCheck && shadowVsRangeCheck;
return isBearishHammer;
}
}
exports.default = BearishHammerStick;
function bearishhammerstick(data, config = DEFAULT_BEARISH_HAMMER_STICK_CONFIG) {
return new BearishHammerStick(config).hasPattern(data);
}
//# sourceMappingURL=BearishHammerStick.js.map