UNPKG

@thuantan2060/technicalindicators

Version:
66 lines (59 loc) 3.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.DEFAULT_THREE_WHITE_SOLDIERS_CONFIG = void 0; exports.threewhitesoldiers = threewhitesoldiers; 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 ThreeWhiteSoldiers pattern. * Only uses the scale parameter for approximateEqual function precision. */ /** * Default configuration for ThreeWhiteSoldiers pattern. */ const DEFAULT_THREE_WHITE_SOLDIERS_CONFIG = exports.DEFAULT_THREE_WHITE_SOLDIERS_CONFIG = { ..._CandlestickFinder.DEFAULT_CANDLESTICK_CONFIG }; class ThreeWhiteSoldiers extends _CandlestickFinder.default { constructor(config) { const finalConfig = { ...DEFAULT_THREE_WHITE_SOLDIERS_CONFIG, ...config }; super(finalConfig); this.name = 'ThreeWhiteSoldiers'; 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]; // All three days should be bullish (white/green candles) - direct price comparisons let isAllBullish = firstClose > firstOpen && secondClose > secondOpen && thirdClose > thirdOpen; // Progressive uptrend - each day should have higher highs (no scale dependency) let isUpTrend = secondHigh > firstHigh && thirdHigh > secondHigh; // Each subsequent day should open within the previous day's body // and close higher than the previous day's close (direct price comparisons) let doesOpenWithinPreviousBody = secondOpen > firstOpen && secondOpen < firstClose && thirdOpen > secondOpen && thirdOpen < secondClose; return isUpTrend && isAllBullish && doesOpenWithinPreviousBody; } } exports.default = ThreeWhiteSoldiers; function threewhitesoldiers(data, config = DEFAULT_THREE_WHITE_SOLDIERS_CONFIG) { return new ThreeWhiteSoldiers(config).hasPattern(data); } //# sourceMappingURL=ThreeWhiteSoldiers.js.map