@cmike444/supply-and-demand-zones
Version:
A library for identifying supply and demand zones in candlestick data.
28 lines (27 loc) • 1.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.findPatternEnd = void 0;
/**
* Finds the index of the first candle that does not satisfy the given condition,
* starting from a specified index and optionally limiting the number of candles to check.
*
* @param candles - An array of `Candle` objects to search through.
* @param startIndex - The index to start searching from.
* @param condition - A callback function that takes a `Candle` and returns a boolean
* indicating whether the candle satisfies the condition.
* @param maxCount - (Optional) The maximum number of candles to check. If not provided,
* the function will continue until the condition is not met or the end of the array is reached.
* @returns The index of the first candle that does not satisfy the condition, or the end of the array
* if all checked candles satisfy the condition.
*/
const findPatternEnd = (candles, startIndex, condition, maxCount) => {
let count = 0;
while (startIndex < candles.length &&
condition(candles[startIndex]) &&
(maxCount === undefined || count < maxCount)) {
startIndex++;
count++;
}
return startIndex;
};
exports.findPatternEnd = findPatternEnd;