Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

candlestick

cm45t3r107MIT0.0.7

JavaScript library for candlestick patterns detection.

candlestick-data, candlestick-pattern-detection, candlestick-pattern, candlestick-patterns-detection, candlestick-patterns, candlestick, candlesticks-pattern, candlesticks, javascript-library, javascript, ohlc, technical-analysis-indicators, technical-analysis-library, technical-analysis-methods, technical-analysis, technical-indicators

readme

Candlestick

Node.js CI workflow npm version

A JavaScript library for candlestick pattern detection. Easy to use and solves the need for node-gyp builds.

Installation

To use the most recent release in your project:

npm install --save candlestick

Available functions

Boolean pattern detection

  • isHammer(candlestick)
  • isInvertedHammer(candlestick)
  • isBullishHammer(candlestick)
  • isBearishHammer(candlestick)
  • isBullishInvertedHammer(candlestick)
  • isBearishInvertedHammer(candlestick)
  • isHangingMan(previous, current)
  • isShootingStar(previous, current)
  • isBullishEngulfing(previous, current)
  • isBearishEngulfing(previous, current)
  • isBullishHarami(previous, current)
  • isBearishHarami(previous, current)
  • isBullishKicker(previous, current)
  • isBearishKicker(previous, current)

Search patterns in arrays

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

candlestick, previous and current are OHLC (Open, High, Low, Close) objects:

{
  open: number,   // security's opening price
  high: number,   // security's highest price
  low: number,    // security's lowest price
  close: number   // security's closing price
}

dataArray is an array of OHLC objects like previous or current.

Note: OHLC objects can have more fields and does not affect the final result.

=== :warning: BREAKING CHANGE WARNING ON VERSIONS >= 0.0.6 ===

Before: search pattern functions returned the last OHLC object conforming the pattern. After: they return the first index of the candle conforming the pattern. It helps locating candlestick in dataArray more easily. So before upgrading to version 0.0.6, please be aware of changing your code.

Examples

Boolean detection

Use two OHLCs to assess the pattern:

const { isBullishKicker, isBearishKicker } = require('candlestick');

// Market data: previous and current ticks
const prev = {
  security: 'ORCL',
  date: '2016-09-15',
  open: 40.18,
  high: 41.03,
  low: 40.09,
  close: 40.86
};

const curr = {
  security: 'ORCL',
  date: '2016-09-16',
  open: 39.61,
  high: 39.35,
  low: 38.71,
  close: 38.92
};

console.log(isBullishKicker(prev, curr)); // false
console.log(isBearishKicker(prev, curr)); // true

Finding patterns in series

Find the points in a dataset where the pattern occurs:

const { shootingStar } = require('candlestick');

// Market data: array of ticks
const data = [
  {
    security: 'GE',
    date: '2016-02-01',
    open: 29.01,
    high: 29.03,
    low: 28.56,
    close: 28.64
  },
  { ... },
  { ... },
  ...
  { ... }
];

console.log(shootingStar(data));
// result: [{ security: 'GE', date: '2016-02-10', ... }, { security: 'GE', date: '2016-07-11', ... }]

Running tests

npm test

Contributing

You are welcome to contribute to this library creating new issues or pull requests.

License

This project is licensed under the MIT license. See the LICENSE file for more info.

changelog

0.0.1 / 2016-10-22

  • Initial release

0.0.2 / 2016-10-24

  • Fixed accidental lib and test folder exclusion on npm package.

0.0.3 / 2016-10-25

  • Shooting star support added.
  • Examples updated.

0.0.4 / 2021-01-12

0.0.5 / 2022-04-28

  • Dependencies upgrade.
  • Add google eslint ruleset.
  • Add nyc coverage to test script.
  • Fix spacing and style.
  • Add jsdoc to functions.
  • Add bullish and bearish hammers (inverted and non-inverted).
  • Add optional ratio param to hammers.
  • Fix kickers to exclude hammers.
  • Fix candle wrapping on engulfings.

0.0.6 / 2024-03-31

  • Remove optional param ratio from hammer functions causing bad results.
  • Fix bullishHammer, bearishHammer, bullishInvertedHammer, bearishInvertedHammer, and hangingMan functions.
  • Bugfix #1.

0.0.7 / 2024-04-02

  • Fix index.js copyright.
  • Remove useless properties in .eslintcr and add object-curly-spacing exception rule.
  • Fix linting errors.
  • Update package keywords and increment version.
  • Optimize private function findPattern to make it more performant.