UNPKG

@thuantan2060/technicalindicators

Version:
141 lines (127 loc) 5.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.DEFAULT_SHOOTING_STAR_CONFIG = void 0; exports.shootingstar = shootingstar; var _CandlestickFinder = _interopRequireWildcard(require("./CandlestickFinder")); var _AverageLoss = require("../Utils/AverageLoss"); var _AverageGain = require("../Utils/AverageGain"); var _BearishInvertedHammerStick = require("./BearishInvertedHammerStick"); var _BullishInvertedHammerStick = require("./BullishInvertedHammerStick"); 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 ShootingStar pattern. * Only requires scale parameter since this pattern uses direct price comparisons. */ /** * Default configuration for ShootingStar pattern. */ const DEFAULT_SHOOTING_STAR_CONFIG = exports.DEFAULT_SHOOTING_STAR_CONFIG = { ..._CandlestickFinder.DEFAULT_CANDLESTICK_CONFIG }; class ShootingStar extends _CandlestickFinder.default { constructor(config) { const finalConfig = { ...DEFAULT_SHOOTING_STAR_CONFIG, ...config }; super(finalConfig); this.name = 'ShootingStar'; this.requiredCount = 5; } logic(data) { // Validate data integrity first for (let i = 0; i < data.close.length; i++) { if (!this.validateOHLC(data.open[i], data.high[i], data.low[i], data.close[i])) { return false; } } let isPattern = this.upwardTrend(data); isPattern = isPattern && this.includesInvertedHammer(data); isPattern = isPattern && this.hasConfirmation(data); return isPattern; } upwardTrend(data, confirm = true) { let end = confirm ? 3 : 4; // Ensure we have enough data if (data.close.length < end) { return false; } // Analyze trends in closing prices of the first three or four candlesticks // For ascending order data, we look at the first 'end' elements let gains = (0, _AverageGain.averagegain)({ values: data.close.slice(0, end), period: end - 1 }); let losses = (0, _AverageLoss.averageloss)({ values: data.close.slice(0, end), period: end - 1 }); // Get the latest values from the arrays let latestGain = gains.length > 0 ? gains[gains.length - 1] : 0; let latestLoss = losses.length > 0 ? losses[losses.length - 1] : 0; // Additional validation: ensure there's actual price movement let closeSlice = data.close.slice(0, end); let priceRange = Math.max(...closeSlice) - Math.min(...closeSlice); let minMovement = priceRange * 0.01; // At least 1% movement // Upward trend, so more gains than losses, and significant movement return latestGain > latestLoss && latestGain > minMovement; } includesInvertedHammer(data, confirm = true) { // For ascending order data, the shooting star is at index 3 (4th candle) let start = 3; let end = 4; // Ensure we have the required data if (data.close.length <= start) { return false; } let possibleHammerData = { open: data.open.slice(start, end), close: data.close.slice(start, end), low: data.low.slice(start, end), high: data.high.slice(start, end) }; // Use the updated inverted hammer functions with config objects let isPattern = (0, _BearishInvertedHammerStick.bearishinvertedhammerstick)(possibleHammerData, _BearishInvertedHammerStick.DEFAULT_BEARISH_INVERTED_HAMMER_CONFIG); isPattern = isPattern || (0, _BullishInvertedHammerStick.bullishinvertedhammerstick)(possibleHammerData, _BullishInvertedHammerStick.DEFAULT_BULLISH_INVERTED_HAMMER_STICK_CONFIG); return isPattern; } hasConfirmation(data) { // Ensure we have enough data if (data.close.length < 5) { return false; } // For ascending order data: // Index 3 = shooting star (4th candle) // Index 4 = confirmation candle (5th candle, most recent) let possibleStar = { open: data.open[3], close: data.close[3], low: data.low[3], high: data.high[3] }; let possibleConfirmation = { open: data.open[4], close: data.close[4], low: data.low[4], high: data.high[4] }; // Validate OHLC data if (!this.validateOHLC(possibleStar.open, possibleStar.high, possibleStar.low, possibleStar.close) || !this.validateOHLC(possibleConfirmation.open, possibleConfirmation.high, possibleConfirmation.low, possibleConfirmation.close)) { return false; } // Confirmation candlestick should be bearish (shooting star is bearish reversal) let isBearishConfirmation = possibleConfirmation.open > possibleConfirmation.close; // The confirmation should close lower than the shooting star's close // and show meaningful downward movement let downwardMovement = possibleStar.close - possibleConfirmation.close; let minMovement = (possibleStar.high - possibleStar.low) * 0.1; // At least 10% of star's range return isBearishConfirmation && downwardMovement > 0 && downwardMovement >= minMovement; } } exports.default = ShootingStar; function shootingstar(data, config = DEFAULT_SHOOTING_STAR_CONFIG) { return new ShootingStar(config).hasPattern(data); } //# sourceMappingURL=ShootingStar.js.map