Skip to content

Commit

Permalink
Merge pull request #15 from cm45t3r/fix/hammers
Browse files Browse the repository at this point in the history
fix(candlestick): Fix hammer functions.
  • Loading branch information
cm45t3r authored Mar 31, 2024
2 parents 4fee63a + ccdf7e9 commit 5cb30fb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
6 changes: 5 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@
* 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.
* 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.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "candlestick",
"version": "0.0.5",
"version": "0.0.6",
"description": "JavaScript library for candlestick patterns detection.",
"homepage": "https://github.com/cm45t3r/candlestick",
"author": {
Expand Down
20 changes: 9 additions & 11 deletions src/candlestick.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,10 @@ function findPattern(dataArray, callback) {
*
* @param {Object} candlestick - object with fields
* `{ open: number, high: number, low: number, close: number }`
* @param {number} ratio - minimum `tail:body` ratio on a hammer.
* @return {boolean} a boolean.
*/
function isHammer(candlestick, ratio = 2) {
return tailLen(candlestick) > (bodyLen(candlestick) * ratio) &&
function isHammer(candlestick) {
return tailLen(candlestick) > (bodyLen(candlestick) * 2) &&
wickLen(candlestick) < bodyLen(candlestick);
}

Expand All @@ -161,11 +160,10 @@ function findPattern(dataArray, callback) {
*
* @param {Object} candlestick - object with fields
* `{ open: number, high: number, low: number, close: number }`
* @param {number} ratio - minimum `tail:body` ratio on a hammer.
* @return {boolean} a boolean.
*/
function isInvertedHammer(candlestick, ratio = 2) {
return wickLen(candlestick) > (bodyLen(candlestick) * ratio) &&
function isInvertedHammer(candlestick) {
return wickLen(candlestick) > (bodyLen(candlestick) * 2) &&
tailLen(candlestick) < bodyLen(candlestick);
}

Expand Down Expand Up @@ -376,7 +374,7 @@ function invertedHammer(dataArray) {
* @return {Array} array of matches.
*/
function bullishHammer(dataArray) {
return findPattern(dataArray, isHammer);
return findPattern(dataArray, isBullishHammer);
}

/**
Expand All @@ -387,7 +385,7 @@ function invertedHammer(dataArray) {
* @return {Array} array of matches.
*/
function bearishHammer(dataArray) {
return findPattern(dataArray, isHammer);
return findPattern(dataArray, isBearishHammer);
}

/**
Expand All @@ -398,7 +396,7 @@ function invertedHammer(dataArray) {
* @return {Array} array of matches.
*/
function bullishInvertedHammer(dataArray) {
return findPattern(dataArray, isHammer);
return findPattern(dataArray, isBullishInvertedHammer);
}

/**
Expand All @@ -409,7 +407,7 @@ function invertedHammer(dataArray) {
* @return {Array} array of matches.
*/
function bearishInvertedHammer(dataArray) {
return findPattern(dataArray, isHammer);
return findPattern(dataArray, isBearishInvertedHammer);
}

/**
Expand All @@ -420,7 +418,7 @@ function invertedHammer(dataArray) {
* @return {Array} array of matches.
*/
function hangingMan(dataArray) {
return findPattern(dataArray, isShootingStar);
return findPattern(dataArray, isHangingMan);
}

/**
Expand Down

0 comments on commit 5cb30fb

Please sign in to comment.