@thuantan2060/technicalindicators
Version:
Techincal Indicators written in javascript
84 lines (79 loc) • 3.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.DEFAULT_DOJI_CONFIG = void 0;
exports.doji = 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 Doji pattern.
* Includes body tolerance thresholds for determining when open equals close.
*/
/**
* Default configuration for Doji pattern.
*/
const DEFAULT_DOJI_CONFIG = exports.DEFAULT_DOJI_CONFIG = {
..._CandlestickFinder.DEFAULT_CANDLESTICK_CONFIG
};
class Doji extends _CandlestickFinder.default {
bodyTolerancePercent;
bodyToleranceMinimum;
constructor(config) {
const finalConfig = {
...DEFAULT_DOJI_CONFIG,
...config
};
super(finalConfig);
this.name = 'Doji';
this.requiredCount = 1;
}
logic(data) {
let daysOpen = data.open[0];
let daysClose = data.close[0];
let daysHigh = data.high[0];
let daysLow = data.low[0];
// A Doji is simply when open equals close (very small or no body)
// The shadows can be of any length
// Note: approximateEqual uses scale parameter for backward compatibility
let isOpenEqualsClose = this.approximateEqual(daysOpen, daysClose);
// Make sure we have valid OHLC data (high >= low, etc.)
let hasValidData = daysHigh >= Math.max(daysOpen, daysClose) && daysLow <= Math.min(daysOpen, daysClose);
return isOpenEqualsClose && hasValidData;
}
}
/**
* Detects Doji candlestick pattern in the provided stock data.
*
* A Doji is a candlestick pattern where the opening and closing prices are virtually equal,
* creating a cross-like appearance. This pattern indicates market indecision and potential
* trend reversal points.
*
* @param data - Stock data containing OHLC values
* @param config - Configuration object for pattern detection
* @param config.scale - Scale parameter for approximateEqual function precision (default: 0.001)
* @param config.bodyTolerancePercent - Body tolerance as percentage of body size (default: 0.015 = 1.5%)
* @param config.bodyToleranceMinimum - Minimum body tolerance absolute value (default: 0.00015)
* @returns True if Doji pattern is detected, false otherwise
*
* @example
* ```typescript
* // Using default configuration
* const hasDojiPattern = doji(stockData);
*
* // Using custom configuration
* const hasDojiPattern = doji(stockData, {
* scale: 0.002,
* bodyTolerancePercent: 0.02,
* bodyToleranceMinimum: 0.0002
* });
*
* // Backward compatibility with scale parameter
* const hasDojiPattern = doji(stockData, { scale: 0.002 });
* ```
*/
exports.default = Doji;
function doji(data, config = DEFAULT_DOJI_CONFIG) {
return new Doji(config).hasPattern(data);
}
//# sourceMappingURL=Doji.js.map