anandanand84 / technicalindicators

A javascript technical indicators written in typescript with pattern recognition right in the browser
MIT License
2.15k stars 557 forks source link

Add Hammers, Hanging Man, and Shooting Star Candlestick Detection #144

Closed marcus-n3rd closed 6 years ago

marcus-n3rd commented 6 years ago

Related Issues

Feature Request : Candle Stick Pattern Hammer Identification: #75

Changes Made

Indicator Logic

Single-Day Candlestick Hammers

Hammer Stick

  1. Bearish or bullish based on open and close values
  2. high value is approximately equal to the open or close value, depending on if bearish or bullish, respective
  3. The lower shadow is at least 2x the size of the real body

Single-Day Candlestick Inverted Hammers

Inverted Hammer Stick

  1. Bearish or bullish based on open and close values
  2. low value is approximately equal to the close or open value, depending on if bearish or bullish, respectively
  3. The upper shadow is at least 2x the size of the real body

Five-Day Candlestick Hammers

Hammer Pattern

  1. Downward trend is determined from the first three days of closing data (indexes 0, 1, and 2)
    1. I originally wanted to use regression calculations here, but there wasn't anything readily available for typescript, so instead...
    2. AverageGain and AverageLoss are used to extract the respective values from the subset
    3. If losses are greater than gains, then downward trend is true
  2. The fourth day's data is true for any single-day candlestick hammer pattern:
    • Bearish Hammer
    • Bearish Inverted Hammer
    • Bullish Hammer
    • Bullish Inverted Hammer
  3. The fifth day's data confirms a change in trend
    1. Bullish candlestick
    2. Closing value is greater than the fourth day's closing value

Five-Day Candlestick Hammers (Unconfirmed)

Unconfirmed Hammer Pattern

  1. Downward trend is determined from the first four days of closing data (indexes 0, 1, 2, and 3)
    1. AverageGain and AverageLoss are used to extract the respective values from the subset
    2. If losses are greater than gains, then downward trend is true
  2. The fifth day's data is true for any single-day candlestick hammer pattern:
    • Bearish Hammer
    • Bearish Inverted Hammer
    • Bullish Hammer
    • Bullish Inverted Hammer

Five-Day Candlestick Hanging Man

Hanging Man

  1. Upward trend is determined from the first three days of closing data (indexes 0, 1, and 2)
    1. AverageGain and AverageLoss are used to extract the respective values from the subset
    2. If gains are greater than losses, then upward trend is true
  2. The fourth day's data is true for any of the following single-day candlestick hammer pattern:
    • Bearish Hammer
    • Bullish Hammer
  3. The fifth day's data confirms a change in trend
    1. Bearish candlestick
    2. Closing value is less than the fourth day's closing value

Five-Day Candlestick Hanging Man (Unconfirmed)

Unconfirmed Hanging Man

  1. Upward trend is determined from the first four days of closing data (indexes 0, 1, 2, and 3)
    1. AverageGain and AverageLoss are used to extract the respective values from the subset
    2. If gains are greater than losses, then upward trend is true
  2. The fifth day's data is true for any of the following single-day candlestick hammer pattern:
    • Bearish Hammer
    • Bullish Hammer

Five-Day Candlestick Shooting Star

Shooting Star

  1. Upward trend is determined from the first three days of closing data (indexes 0, 1, and 2)
    1. AverageGain and AverageLoss are used to extract the respective values from the subset
    2. If gains are greater than losses, then upward trend is true
  2. The fourth day's data is true for any of the following single-day candlestick hammer pattern:
    • Bearish Inverted Hammer
    • Bullish Inverted Hammer
  3. The fifth day's data confirms a change in trend
    1. Bearish candlestick
    2. Closing value is less than the fourth day's closing value

Five-Day Candlestick Shooting Star (Unconfirmed)

Unconfirmed Shooting Star

  1. Upward trend is determined from the first four days of closing data (indexes 0, 1, 2, and 3)
    1. AverageGain and AverageLoss are used to extract the respective values from the subset
    2. If gains are greater than losses, then upward trend is true
  2. The fifth day's data is true for any single-day candlestick hammer pattern:
    • Bearish Inverted Hammer
    • Bullish Inverted Hammer
anandanand84 commented 6 years ago

Wow, Thats awesome, I'll merge it. Is the image that is shown are from the tests ran?

marcus-n3rd commented 6 years ago

Yes, those are the images generated during the tests. There are more images from other scenarios, but I only wanted to use one-per in the PR.

anandanand84 commented 6 years ago

@marcus-n3rd I have merged the PR. One thing that was missing is adding the patterns into the more generic bullish and bearish file, which calculates all bullish and bearish candlestick patterns, which you can see here.

https://github.com/anandanand84/technicalindicators/blob/master/src/candlestick/Bullish.ts#L13

I'll add those in the next release. Thanks again for contributing.