Git Product home page Git Product logo

candlestickpattern's Introduction

CandleStickPattern

This package finds common candle stick patterns using daily data (OHLC data).

Overview

The current version package covers the following patterns:

  • Doji family (1-day pattern)
    • Doji doji()
    • Dragonfly Doji dragonfly.doji()
    • Gravestone Doji gravestone.doji()
  • Hammer family (2-day pattern)
    • Hammer/Hangman hammer()
    • Inverted Hammer/Shooting Star inverted.hammer
  • Engulfing family (2-day pattern)
    • Bullish Engulfing bullish.engulf()
    • Bearish Engulfing bearish.engulf()
  • Harami family (2-day pattern)
    • Bullish Harami bullish.engulf()
    • Bearish Harami bearish.harami()
  • Reversal family (2-day pattern)
    • Piercing line piercing.line()
    • Dark cloud Cover dark.cloud.cover()
  • Kicking family (2-day pattern)
    • Kick up kick.up()
    • Kick down kick.down()
  • Three-in-a-row (3-day pattern)
    • Three white soldiers three.white.soliders()
    • Three Black crows three.black.crows()
  • Star (3-day pattern)
    • Morning star morning.star()
    • Evening star evening.star()
  • Three Method (5-day pattern)
    • Rising three rising.three()
    • Falling three falling.three()

Moreover, it captures trends using exponential moving average (EMA):

  • EMA trends
    • up trend up.trend()
    • down trend down.trend()

Installation

To install this package, it is the easist to install devtools package first:

install.packages("devtools")

Now load the package using library()

library(devtools)

Then we can use the install_github to get the package directly:

install_github("kochiuyu/CandleStickPattern")

Finally, we load the package using library()

library(CandleStickPattern)

Usage

You can see the details of how each function works in vignette

The following demonstrates the usage of the function doji() using Microsoft (ticker: MSFT). We use quantmod package to download data:

library(quantmod)
getSymbols("MSFT", from = "2011-07-08" , to = "2011-07-19")

We first plot the candle chart first:

candleChart(MSFT,theme='white')

We can see that July 11, 12, 13, and 18 are likely to follow doji pattern. Let us see if we can capture using the function doji:

doji(MSFT)
##             doji
## 2011-07-08 FALSE
## 2011-07-11  TRUE
## 2011-07-12  TRUE
## 2011-07-13  TRUE
## 2011-07-14 FALSE
## 2011-07-15 FALSE
## 2011-07-18  TRUE
## 2011-07-19 FALSE

candlestickpattern's People

Contributors

kochiuyu 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

Watchers

 avatar  avatar  avatar

candlestickpattern's Issues

Review of documentation

Hi @kochiuyu,

I have re-written all the code such that it works with any data type, and added documentation where there were none - or it was too little. This has introduced some inconsistencies in the code which needs to be resolved; and then there has been instances of the documentation not aligning with the actual code.

I have done my best to collect everything this issue, if anything is missing it is not something that have caught my interest. Remember to add your name to all functions that belongs to you.

Note: all these are located on the development-branch
of the repository.

Inconsistent documentation and code

Trend-functions

#' Determine up trend based on moving average using a OHLC price series
#'
#' @description
#' `r lifecycle::badge("experimental")`
#'
#' @param ohlc OHLC prices.
#' @param delta sensitivity
#' @param S number of short period for short-run moving average
#' @param L number of short period for short-run SMA
#'
#'
#' @family Trend patterns
#'
#' @returns length of upper shadow
#' @export
trend_up <- function(
ohlc,
delta=0.01,
S=5,
L=20) {
# check ohlc input
# before anything
is_ohlc(ohlc = ohlc)
close_price <- extract_column(
ohlc,
pattern = "close",
column_names = colnames(ohlc)
)
r <- TTR::EMA(close_price,n=S)/TTR::EMA(close_price,n=L)-1
r > delta
}

#' Determine down trend based on moving average using a OHLC price series
#'
#' @description
#' `r lifecycle::badge("experimental")`
#'
#' @param ohlc OHLC prices.
#' @param delta sensitivity
#' @param S number of short period for short-run moving average
#' @param L number of short period for short-run SMA
#'
#' @family Trend patterns
#'
#' @returns length of upper shadow
#' @export
trend_down <- function(
ohlc,
delta=0.01,
S=5,
L=20) {
# check ohlc input
# before anything
is_ohlc(ohlc = ohlc)
close_price <- extract_column(
ohlc,
pattern = "close",
column_names = colnames(ohlc)
)
r <- TTR::EMA(close_price,n=S)/TTR::EMA(close_price,n=L)-1
r < (-delta)
}

  • The documentation mentions SMA, but doesnt use it.

Star pattern

#' Determine morning star pattern using a OHLC price series
#'
#' @description
#' `r lifecycle::badge("experimental")`
#'
#'
#' @param ohlc A [data.frame] containing Open, High, Low, Close prices
#' @param n number of period of trend
#' @param delta A named [list] of sensitivity parameters
#'
#' @family star
#'
#' @returns TRUE if kicking up pattern detected
#'
#' @author Chiu-Yu Ko
#'
#' @example man/examples/scr_star.R
#'
#' @export
morning_star <- function(
ohlc,
n = 20,
delta = list(
long_candle = 1,
short_candle = 1
)) {
# check ohlc input
# before anything
is_ohlc(ohlc = ohlc)
bull_candle <- bullish_candle(ohlc)
bear_candle <- bearish_candle(ohlc)
l_bear_candle <- xts::lag.xts(bear_candle,2)
long_candle <- candle_feature(ohlc = ohlc,feature = 'is_long',n = n, delta = delta$long_candle)
l_long_candle <- xts::lag.xts(long_candle,2)
short_candle <- candle_feature(ohlc = ohlc,feature = 'is_short',n = n, delta = delta$short_candle)
l_short_candle <- xts::lag.xts(short_candle)
upside_gap <- gap_up(ohlc)
downside_gap <- gap_down(ohlc)
l_downside_gap <- xts::lag.xts(downside_gap)
bull_candle & long_candle & l_short_candle & l_bear_candle & l_long_candle & upside_gap & l_downside_gap
}

#' Determine evening star pattern using a OHLC price series
#'
#' @description
#' `r lifecycle::badge("experimental")`
#'
#'
#' @param ohlc A [data.frame] containing Open, High, Low, Close prices
#' @param n number of period of trend
#' @param delta A named [list] of sensitivity parameters
#'
#' @family star
#'
#' @returns TRUE if kicking up pattern detected
#'
#' @author Chiu-Yu Ko
#'
#' @example man/examples/scr_star.R
#'
#' @export
evening_star <- function(
ohlc,
n = 20,
delta = list(
long_candle = 1,
short_candle = 1
)) {
# check ohlc input
# before anything
is_ohlc(ohlc = ohlc)
bull_candle <- bullish_candle(ohlc)
bear_candle <- bearish_candle(ohlc)
l_bull_candle <- xts::lag.xts(bull_candle,2)
long_candle <- candle_feature(ohlc = ohlc,feature = 'is_long',n = n, delta = delta$long_candle)
l_long_candle <- xts::lag.xts(long_candle,2)
short_candle <- candle_feature(ohlc = ohlc,feature = 'is_short',n = n, delta = delta$short_candle)
l_short_candle <- xts::lag.xts(short_candle)
upside_gap <- gap_up(ohlc)
downside_gap <- gap_down(ohlc)
l_downside_gap <- xts::lag.xts(upside_gap)
bear_candle & long_candle &
l_short_candle &
l_bull_candle & l_long_candle &
downside_gap &
l_downside_gap
}

  • The documentation mentions #' @returns TRUE if kicking up pattern detected, does the function calculate what you expect it to?

Piercing line pattern

# script: Piercing Line Pattern
# date: 2024-02-12
# author: Serkan Korkmaz, [email protected]
# objective: Collect the piercing line pattern
# script start;
#
#' Determine piercing line pattern using a OHLC price series
#' @description
#' `r lifecycle::badge("experimental")`
#' @param ohlc OHLC prices.
#' @return TRUE if hammer pattern detected
#' @export
piercing_line <- function(ohlc) {
# check ohlc input
# before anything
is_ohlc(ohlc = ohlc)
close_price <- extract_column(
ohlc,
pattern="close",
column_names = colnames(ohlc)
)
body_center <- body_feature(
ohlc,
feature = "center"
)
l_body_center <- xts::lag.xts(body_center)
bull_candle <- bullish_candle(ohlc)
bear_candle <- bearish_candle(ohlc)
l_bear_candle <- xts::lag.xts(bear_candle)
bull_candle &
l_bear_candle &
close_price >= l_body_center
}
# script end;

  • The documentation mentions #' @return TRUE if hammer pattern detected, does the function calculate what you expect it to?

Streamlining documentation

The title tag of the roxygen-documentation should be streamlined, in the hammer-pattern the title tag says,

#' Identify Hammer patterns in OHLC-series

while the harami-pattern says,

#' Determine bearish harami pattern using a OHLC price series

A skeleton to follow

#' @title 
#'
#' @description
#'
#' @example "path to example"
#'
#'
#' @param x param_description
#' @param y param_description
#'
#' @details
#'
#' @family
#' @family
#'
#' @returns 
#'
#' @author

See more here https://r-pkgs.org/

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.