@thuantan2060/technicalindicators
Version:
Techincal Indicators written in javascript
77 lines (72 loc) • 3.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.DEFAULT_MORNING_DOJI_STAR_CONFIG = void 0;
exports.morningdojistar = morningdojistar;
var _Doji = require("./Doji");
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 MorningDojiStar pattern.
* Only requires scale parameter since this pattern uses direct price comparisons.
*/
/**
* Default configuration for MorningDojiStar pattern.
*/
const DEFAULT_MORNING_DOJI_STAR_CONFIG = exports.DEFAULT_MORNING_DOJI_STAR_CONFIG = {
..._CandlestickFinder.DEFAULT_CANDLESTICK_CONFIG,
..._Doji.DEFAULT_DOJI_CONFIG
};
class MorningDojiStar extends _CandlestickFinder.default {
config;
constructor(config) {
const finalConfig = {
...DEFAULT_MORNING_DOJI_STAR_CONFIG,
...config
};
super(finalConfig);
this.name = 'MorningDojiStar';
this.requiredCount = 3;
this.config = finalConfig;
}
logic(data) {
// For ascending order data: [0]=oldest (day 1), [1]=middle (day 2), [2]=newest (day 3)
let firstdaysOpen = data.open[0]; // Day 1 (oldest) - should be bearish candle
let firstdaysClose = data.close[0];
let firstdaysHigh = data.high[0];
let firstdaysLow = data.low[0];
let seconddaysOpen = data.open[1]; // Day 2 (middle) - should be doji star
let seconddaysClose = data.close[1];
let seconddaysHigh = data.high[1];
let seconddaysLow = data.low[1];
let thirddaysOpen = data.open[2]; // Day 3 (newest) - should be bullish candle
let thirddaysClose = data.close[2];
let thirddaysHigh = data.high[2];
let thirddaysLow = data.low[2];
// Validate OHLC data integrity for all three days
let ohlcValid = this.validateOHLC(firstdaysOpen, firstdaysHigh, firstdaysLow, firstdaysClose) && this.validateOHLC(seconddaysOpen, seconddaysHigh, seconddaysLow, seconddaysClose) && this.validateOHLC(thirddaysOpen, thirddaysHigh, thirddaysLow, thirddaysClose);
if (!ohlcValid) {
return false;
}
let firstdaysMidpoint = (firstdaysOpen + firstdaysClose) / 2;
let isFirstBearish = firstdaysClose < firstdaysOpen;
// Use the doji function with proper config object
let dojiExists = (0, _Doji.doji)({
"open": [seconddaysOpen],
"close": [seconddaysClose],
"high": [seconddaysHigh],
"low": [seconddaysLow]
}, this.config);
let isThirdBullish = thirddaysOpen < thirddaysClose;
// Gap conditions: day2 should gap down from day1, day3 should gap up from day2
let gapExists = seconddaysHigh < firstdaysLow && seconddaysLow < firstdaysLow && thirddaysOpen > seconddaysHigh && seconddaysClose < thirddaysOpen;
let doesCloseAboveFirstMidpoint = thirddaysClose > firstdaysMidpoint;
return isFirstBearish && dojiExists && isThirdBullish && gapExists && doesCloseAboveFirstMidpoint;
}
}
exports.default = MorningDojiStar;
function morningdojistar(data, config = DEFAULT_MORNING_DOJI_STAR_CONFIG) {
return new MorningDojiStar(config).hasPattern(data);
}
//# sourceMappingURL=MorningDojiStar.js.map