Coder Social home page Coder Social logo

cm45t3r / candlestick Goto Github PK

View Code? Open in Web Editor NEW
329.0 17.0 72.0 125 KB

Candlestick patterns detection.

License: MIT License

JavaScript 100.00%
candlestick candlesticks candlestick-patterns-detection technical-indicators technical-analysis candlestick-patterns candlestick-data candlestick-pattern candlesticks-pattern javascript

candlestick's Introduction

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.

=== โš ๏ธ 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.

candlestick's People

Contributors

cm45t3r avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

candlestick's Issues

Cannot chain the patterns

The essential value of pattern recognition is in constructing a chain of patterns from an array of candles, i.e. taking an array of candles, and producing an array of [pattern1, pattern2, pattern3,...], so it is possible to use such data to evaluate data predicted by the pattern versus the actual data, which in turn provides evaluation of patterns accuracy/reliance within any given data set.

Currently, the library does not let you construct such pattern chain at all.

So this is a proposed improvement ๐Ÿ˜‰

Non installation fix & possible script error on test?

Let me start by saying that this is exactly what I had been looking for, and was quite surprised that there weren't more projects of this type on here.

Okay now the issue(s)

  1. Easy fix . . . following download and running install, install was rejected due to the project name being the same as one the dependencies in the Package.Json file. - fixed by Capitalising the name of the project in this file and running npm install Candlestick instead of candlestick.

  2. Issue on test (which I'm not going to need, but ran anyway) throwing up

mocha --check-leaks --use_strict

error. May be something in the script?

Should detect Doji patterns.

Currently library functions don't if a candlestick has Doji pattern. This feature needs to be included. It would be better if different versions of Doji pattern i.e. standard, gravestone or dragonfly Doji can be detected.

isEngulfed function

First of all, thank's for sharing this code.
I'm not a python developer but I think there's an issue with isEngulfed function.

Shortest candlestick is engulfed by a longest if the body of longest which completely overlaps or engulfs the body of the shortest

  1. Math.max(shortest.open, shortest.close) < Math.max(longest .open, longest .close)
  2. Math.min(shortest.open, shortest.close) > Math.min(longest .open, longest .close)

if this two conditions are true so bodyLen(shortest) < bodyLen(longest)

Thank's

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.