@thuantan2060/technicalindicators
Version:
Techincal Indicators written in javascript
90 lines (80 loc) • 3.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.DEFAULT_PIERCING_LINE_CONFIG = void 0;
exports.piercingline = piercingline;
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 PiercingLine pattern.
* Only requires scale parameter since this pattern uses direct price comparisons.
*/
/**
* Default configuration for PiercingLine pattern.
*/
const DEFAULT_PIERCING_LINE_CONFIG = exports.DEFAULT_PIERCING_LINE_CONFIG = {
..._CandlestickFinder.DEFAULT_CANDLESTICK_CONFIG
};
class PiercingLine extends _CandlestickFinder.default {
constructor(config) {
const finalConfig = {
...DEFAULT_PIERCING_LINE_CONFIG,
...config
};
super(finalConfig);
this.requiredCount = 2;
this.name = 'PiercingLine';
}
logic(data) {
// Previous day (older) - index 0
let prevOpen = data.open[0];
let prevClose = data.close[0];
let prevHigh = data.high[0];
let prevLow = data.low[0];
// Current day (most recent) - index 1
let currOpen = data.open[1];
let currClose = data.close[1];
let currHigh = data.high[1];
let currLow = data.low[1];
// Validate OHLC data integrity for both days
if (!this.validateOHLC(prevOpen, prevHigh, prevLow, prevClose) || !this.validateOHLC(currOpen, currHigh, currLow, currClose)) {
return false;
}
// Previous day should be bearish (red candle)
let prevIsBearish = prevClose < prevOpen;
// Current day should be bullish (green candle)
let currIsBullish = currClose > currOpen;
// Calculate the midpoint of previous day's body (no scale dependency)
let prevMidpoint = (prevOpen + prevClose) / 2;
// Piercing line conditions (all use direct price comparisons):
// 1. Current opens below previous day's low (gap down)
// 2. Current close is above the midpoint of previous day's body
let isPiercingLine = currOpen < prevLow && currClose > prevMidpoint;
// Additional check: ensure current close is still below previous open (not full engulfment)
let isPartialPenetration = currClose < prevOpen;
return prevIsBearish && currIsBullish && isPiercingLine && isPartialPenetration;
}
}
/**
* Detects PiercingLine candlestick pattern.
*
* A PiercingLine is a bullish reversal pattern that occurs at the end of a downtrend.
* It consists of a bearish candle followed by a bullish candle that opens below the
* previous day's low but closes above the midpoint of the previous day's body.
*
* @param data - Stock data containing OHLC values
* @param config - Configuration options for the pattern detection
* @returns True if PiercingLine pattern is detected, false otherwise
*
* @example
* ```typescript
* const data = { open: [...], high: [...], low: [...], close: [...] };
* const isPattern = piercingline(data, { scale: 0.001 });
* ```
*/
exports.default = PiercingLine;
function piercingline(data, config = DEFAULT_PIERCING_LINE_CONFIG) {
return new PiercingLine(config).hasPattern(data);
}
//# sourceMappingURL=PiercingLine.js.map