UNPKG

@thuantan2060/technicalindicators

Version:
73 lines (65 loc) 3.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.DEFAULT_EVENING_STAR_CONFIG = void 0; exports.eveningstar = eveningstar; 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 EveningStar pattern. * Only requires scale parameter since this pattern uses direct price comparisons. */ /** * Default configuration for EveningStar pattern. */ const DEFAULT_EVENING_STAR_CONFIG = exports.DEFAULT_EVENING_STAR_CONFIG = { ..._CandlestickFinder.DEFAULT_CANDLESTICK_CONFIG }; class EveningStar extends _CandlestickFinder.default { constructor(config) { const finalConfig = { ...DEFAULT_EVENING_STAR_CONFIG, ...config }; super(finalConfig); this.name = 'EveningStar'; this.requiredCount = 3; } logic(data) { // First day (oldest) - index 0 let firstOpen = data.open[0]; let firstClose = data.close[0]; let firstHigh = data.high[0]; let firstLow = data.low[0]; // Second day (middle) - index 1 let secondOpen = data.open[1]; let secondClose = data.close[1]; let secondHigh = data.high[1]; let secondLow = data.low[1]; // Third day (most recent) - index 2 let thirdOpen = data.open[2]; let thirdClose = data.close[2]; let thirdHigh = data.high[2]; let thirdLow = data.low[2]; // First day should be bullish (green candle) let isFirstBullish = firstClose > firstOpen; // Second day should be a small body (star) gapping up from first day let firstMidpoint = (firstOpen + firstClose) / 2; let secondBodySize = Math.abs(secondClose - secondOpen); let firstBodySize = Math.abs(firstClose - firstOpen); let isSmallBody = secondBodySize < firstBodySize * 0.3; // Small relative to first day // Third day should be bearish and close below first day's midpoint let isThirdBearish = thirdClose < thirdOpen; let closesBelowFirstMidpoint = thirdClose < firstMidpoint; // Gap conditions: second day gaps up from first, third gaps down from second let hasUpGap = secondLow > firstHigh; let hasDownGap = thirdOpen < secondLow; return isFirstBullish && isSmallBody && isThirdBearish && closesBelowFirstMidpoint && hasUpGap && hasDownGap; } } exports.default = EveningStar; function eveningstar(data, config = DEFAULT_EVENING_STAR_CONFIG) { return new EveningStar(config).hasPattern(data); } //# sourceMappingURL=EveningStar.js.map