@thuantan2060/technicalindicators
Version:
Techincal Indicators written in javascript
73 lines (65 loc) • 3.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.DEFAULT_MORNING_STAR_CONFIG = void 0;
exports.morningstar = morningstar;
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 MorningStar pattern.
* Only requires scale parameter since this pattern uses direct price comparisons.
*/
/**
* Default configuration for MorningStar pattern.
*/
const DEFAULT_MORNING_STAR_CONFIG = exports.DEFAULT_MORNING_STAR_CONFIG = {
..._CandlestickFinder.DEFAULT_CANDLESTICK_CONFIG
};
class MorningStar extends _CandlestickFinder.default {
constructor(config) {
const finalConfig = {
...DEFAULT_MORNING_STAR_CONFIG,
...config
};
super(finalConfig);
this.name = 'MorningStar';
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 bearish (red candle)
let isFirstBearish = firstClose < firstOpen;
// Second day should be a small body (star) gapping down 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 bullish and close above first day's midpoint
let isThirdBullish = thirdClose > thirdOpen;
let closesAboveFirstMidpoint = thirdClose > firstMidpoint;
// Gap conditions: second day gaps down from first, third gaps up from second
let hasDownGap = secondHigh < firstLow;
let hasUpGap = thirdOpen > secondHigh;
return isFirstBearish && isSmallBody && isThirdBullish && closesAboveFirstMidpoint && hasDownGap && hasUpGap;
}
}
exports.default = MorningStar;
function morningstar(data, config = DEFAULT_MORNING_STAR_CONFIG) {
return new MorningStar(config).hasPattern(data);
}
//# sourceMappingURL=MorningStar.js.map