SkillAgentSearch skills...

Candlestick

Candlestick patterns detection.

Install / Use

/learn @cm45t3r/Candlestick

README

Candlestick

Node.js CI workflow npm npm downloads Bundle Size Coverage Status Known Vulnerabilities ESLint code style: prettier License: MIT PRs Welcome Contributors Last Commit

A modern, modular JavaScript library for candlestick pattern detection. Detects classic reversal and continuation patterns in OHLC data, with a clean API and no native dependencies.

✨ New in this version (v1.2.0):

  • 🎯 19 candlestick patterns, 29 variants (was 16 patterns, +18.75%)
  • 📦 ESM & CommonJS support (dual export)
  • 🔷 Full TypeScript definitions
  • ✅ 306 tests with 99.75% coverage (97.63% branches, 100% functions)
  • 🚀 Streaming API for massive datasets (70% memory reduction)
  • 🔬 Property-based testing with fast-check
  • 🔌 Plugin system for custom patterns
  • ✅ Data validation system
  • 📊 Pattern metadata (confidence, type, strength)
  • 💻 CLI tool for CSV/JSON analysis

Table of Contents


Why Candlestick?

  • No native dependencies: 100% JavaScript, works everywhere Node.js runs.
  • Modular: Each pattern is its own module, easy to extend or customize.
  • Consistent API: All pattern functions use a standard interface.
  • Pattern Chaining: Scan for multiple patterns in a single pass.
  • Comprehensive Test Suite: Each pattern and utility is unit tested.
  • Modern Tooling: Uses ESLint (flat config) and Prettier for code quality and formatting.
  • Actively Maintained: See ROADMAP.md and CHANGELOG.md.

Features

  • 19 Candlestick Patterns (29 variants): Comprehensive pattern detection library
  • Streaming API: Process massive datasets with 70% memory reduction
  • Property-Based Testing: Validated with 1000+ generated test cases
  • Dual Module Support: CommonJS and ESM exports
  • TypeScript: Complete type definitions with IntelliSense
  • Data Validation: Robust OHLC validation system
  • Plugin System: Register custom patterns
  • Pattern Chaining: Multi-pattern detection in single pass
  • Zero Dependencies: Pure JavaScript, works everywhere
  • Excellent Test Coverage: 306 tests with 99.75% coverage (97.63% branches, 100% functions)
  • High Performance: 59K+ candles/sec throughput
  • Well Documented: Architecture guides, examples, and API docs

Quick Start

Installation

npm install candlestick

CommonJS (Node.js)

const { isHammer, hammer, patternChain, allPatterns } = require("candlestick");

// Check single candle
const candle = { open: 10, high: 15, low: 8, close: 14 };
console.log(isHammer(candle)); // true or false

// Find patterns in series
const candles = [
  /* array of OHLC objects */
];
console.log(hammer(candles)); // [indices where pattern found]

// Detect all patterns at once
const results = patternChain(candles, allPatterns);
console.log(results); // [{ index, pattern, match }]

ESM (Modern JavaScript)

import { isHammer, hammer, patternChain, allPatterns } from "candlestick";

const candles = [
  /* array of OHLC objects */
];
const results = patternChain(candles, allPatterns);
console.log(results);

TypeScript

import { OHLC, PatternMatch, patternChain, allPatterns } from "candlestick";

const candles: OHLC[] = [
  { open: 10, high: 15, low: 8, close: 12 },
  { open: 12, high: 16, low: 11, close: 14 },
];

const results: PatternMatch[] = patternChain(candles, allPatterns);
// Full IntelliSense support ✓

Usage

Importing

CommonJS (Node.js):

// Import all patterns
const candlestick = require("candlestick");

// Or import only what you need
const { isHammer, hammer, patternChain } = require("candlestick");

ESM (Modern JavaScript):

// Import all patterns
import candlestick from "candlestick";

// Or import only what you need (recommended for tree-shaking)
import { isHammer, hammer, patternChain } from "candlestick";

OHLC Format

All functions expect objects with at least:

{
  open: Number,
  high: Number,
  low: Number,
  close: Number
}

Pattern Detection Functions

Boolean (Single/Pair) Detection

  • isHammer(candle)
  • isBullishHammer(candle) / isBearishHammer(candle)
  • isInvertedHammer(candle)
  • isBullishInvertedHammer(candle) / isBearishInvertedHammer(candle)
  • isDoji(candle)
  • isBullishEngulfing(prev, curr) / isBearishEngulfing(prev, curr)
  • isBullishHarami(prev, curr) / isBearishHarami(prev, curr)
  • isBullishKicker(prev, curr) / isBearishKicker(prev, curr)
  • isHangingMan(prev, curr)
  • isShootingStar(prev, curr)

Array (Series) Detection

  • hammer(dataArray) / bullishHammer(dataArray) / bearishHammer(dataArray)
  • invertedHammer(dataArray) / bullishInvertedHammer(dataArray) / bearishInvertedHammer(dataArray)
  • doji(dataArray)
  • bullishEngulfing(dataArray) / bearishEngulfing(dataArray)
  • bullishHarami(dataArray) / bearishHarami(dataArray)
  • bullishKicker(dataArray) / bearishKicker(dataArray)
  • hangingMan(dataArray) / shootingStar(dataArray)

All array functions return an array of indices where the pattern occurs.


High-Level Pattern Chaining

Scan a series for multiple patterns in one pass:

const { patternChain, allPatterns } = require("candlestick");

const matches = patternChain(dataArray, allPatterns);
// matches: [
//   { index: 3, pattern: 'hammer', match: [candleObj] },
//   { index: 7, pattern: 'bullishEngulfing', match: [candleObj, candleObj] },
//   ...
// ]

You can also pass a custom list of patterns:

const matches = patternChain(dataArray, [
  { name: "doji", fn: candlestick.doji },
  { name: "bullishEngulfing", fn: candlestick.bullishEngulfing, paramCount: 2 },
]);

Multi-candle patterns: Patterns like Engulfing, Harami, Kicker, Hanging Man, and Shooting Star span two candles. The match array in the result will contain both candles (length 2), thanks to the paramCount property. Single-candle patterns return a single-element array.


Pattern Descriptions

Single Candle Patterns

  • Hammer: Small body near the top (body < 1/3 of range), long lower shadow (tail ≥ 2× body), small upper shadow. Signals possible bullish reversal.
  • Inverted Hammer: Small body near the bottom, long upper shadow (wick ≥ 2× body), small lower shadow. Bullish reversal signal.
  • Doji: Very small body (body < 10% of range), open ≈ close. Indicates indecision. Candle must have range (high > low).
  • Marubozu: Long body (≥ 70% of range) with minimal shadows (< 10% of body). Strong directional move. Bullish Marubozu shows strong buying, Bearish shows strong selling.
  • Spinning Top: Small body (< 30% of range) with long upper and lower shadows (each > 20% of range). Indicates market indecision or potential reversal.

Two Candle Patterns

  • Engulfing: Second candle's body fully engulfs the previous (body range covers previous body). Bullish or bearish.
  • Harami: Second candle's body is inside the previous (body range within previous body). Bullish or bearish.
  • Kicker: Strong reversal with a gap and opposite color. Bullish or bearish.
  • Hanging Man: Bullish candle followed by a bearish hammer with a gap up. Bearish reversal.
  • Shooting Star: Bullish candle followed by a bearish inverted hammer with a gap up. Bearish reversal.
  • Piercing Line: Bullish reversal. Bearish candle followed by bullish candle that opens below first's low and closes above its midpoint.
  • Dark Cloud Cover: Bearish reversal. Bullish candle followed by bearish candle that opens above first's high and closes below its midpoint.
  • Tweezers Top: Bearish reversal. Bullish candle followed by bearish candle with matching highs (within 1% tolerance). Indicates resistance level.
  • Tweezers Bottom: Bullish reversal. Bearish candle followed by bullish candle with matching lows (within 1% tolerance). Indicates support level.

Three Candle Patterns

  • Morning Star: Bullish reversal. Long bearish candle, small-bodied star that gaps down, long bullish
View on GitHub
GitHub Stars466
CategoryDevelopment
Updated1d ago
Forks81

Languages

JavaScript

Security Score

100/100

Audited on Mar 27, 2026

No findings