[Candlesticks-commits] r5 - in pkg: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jan 16 10:52:53 CET 2012


Author: wotuzu17
Date: 2012-01-16 10:52:53 +0100 (Mon, 16 Jan 2012)
New Revision: 5

Added:
   pkg/R/CSPKicking.R
   pkg/R/CSPThreeInside.R
   pkg/R/CSPThreeOutside.R
   pkg/man/CSPInsideDay.Rd
   pkg/man/CSPKicking.Rd
   pkg/man/CSPThreeInside.Rd
   pkg/man/CSPThreeOutside.Rd
Modified:
   pkg/DESCRIPTION
   pkg/NAMESPACE
   pkg/R/CSPDoji.R
   pkg/R/CSPHarami.R
   pkg/man/CSPDoji.Rd
   pkg/man/CSPNLongWhiteCandles.Rd
Log:
added various functions and documentation

Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION	2012-01-15 12:25:12 UTC (rev 4)
+++ pkg/DESCRIPTION	2012-01-16 09:52:53 UTC (rev 5)
@@ -1,8 +1,8 @@
 Package: candlesticks
 Type: Package
 Title: Candlestick Pattern Recognition
-Version: 0.1-3
-Date: 2012-01-15
+Version: 0.1-5
+Date: 2012-01-16
 Author: Andreas Voellenklee
 Maintainer: Andreas Voellenklee <wotuzu17 at gmail.com>
 Depends: R (>= 2.13), xts (>= 0.8-2), quantmod (>= 0.3-17), TTR (>= 0.21-0)

Modified: pkg/NAMESPACE
===================================================================
--- pkg/NAMESPACE	2012-01-15 12:25:12 UTC (rev 4)
+++ pkg/NAMESPACE	2012-01-16 09:52:53 UTC (rev 5)
@@ -5,6 +5,7 @@
 export(CSPGap)
 export(CSPHarami)
 export(CSPInsideDay)
+export(CSPKicking)
 export(CSPLongCandle)
 export(CSPLongCandleBody)
 export(CSPNHigherClose)
@@ -21,6 +22,8 @@
 export(CSPStar)
 export(CSPStomache)
 export(CSPThreeBlackCrows)
+export(CSPThreeInside)
+export(CSPThreeOutside)
 export(CSPThreeWhiteSoldiers)
 # lag functions
 export(LagOHLC)

Modified: pkg/R/CSPDoji.R
===================================================================
--- pkg/R/CSPDoji.R	2012-01-15 12:25:12 UTC (rev 4)
+++ pkg/R/CSPDoji.R	2012-01-16 09:52:53 UTC (rev 5)
@@ -2,7 +2,10 @@
   if (!is.OHLC(TS)) {
     stop("Price series must contain Open, High, Low and Close.")
   }
-  Doji <- eval ( abs(Op(TS)-Cl(TS))/(Hi(TS)-Lo(TS)) <= DojiBLRatio)
-  colnames(Doji) <- c("Doji")
-  return (Doji)
+  Doji <- eval (abs(Op(TS)-Cl(TS))/(Hi(TS)-Lo(TS)) <= DojiBLRatio)
+  DFDoji <- eval (Doji & (Op(TS)==Hi(TS) | Cl(TS)==Hi(TS)))
+  GSDoji <- eval (Doji & (Op(TS)==Lo(TS) | Cl(TS)==Lo(TS)))  
+  result <- cbind(Doji, DFDoji, GSDoji)
+  colnames(result) <- c("Doji", "DragonflyDoji", "GravestoneDoji")
+  return (result)
 }

Modified: pkg/R/CSPHarami.R
===================================================================
--- pkg/R/CSPHarami.R	2012-01-15 12:25:12 UTC (rev 4)
+++ pkg/R/CSPHarami.R	2012-01-16 09:52:53 UTC (rev 5)
@@ -14,8 +14,8 @@
   # some don't accept the second candle being a doji
   if (excludeDoji==TRUE) {
     Doji <- CSPDoji(TS, DojiBLRatio)
-    BullHarami <- eval(BullHarami & !Doji)
-    BearHarami <- eval(BearHarami & !Doji)
+    BullHarami <- eval(BullHarami & !Doji[,1])
+    BearHarami <- eval(BearHarami & !Doji[,1])
   }
   result <- cbind(BullHarami, BearHarami)
   colnames(result) <- c("Bull.Harami", "Bear.Harami")

Added: pkg/R/CSPKicking.R
===================================================================
--- pkg/R/CSPKicking.R	                        (rev 0)
+++ pkg/R/CSPKicking.R	2012-01-16 09:52:53 UTC (rev 5)
@@ -0,0 +1,28 @@
+CSPKicking <- function(TS, ignoreShadows=TRUE, n=20, threshold=1.5) {
+  if (!is.OHLC(TS)) {
+    stop("Price series must contain Open, High, Low and Close.")
+  }
+  TSGAP <- CSPGap(TS, ignoreShadows=ignoreShadows)
+  if (ignoreShadows==FALSE) {
+    MB <- CSPMarubozu(TS, n=n, threshold=threshold)
+    WMB1 <- Lag(MB[,1], k=1)
+    BMB1 <- Lag(MB[,4], k=1)
+    BULLK <- eval(TSGAP[,1] &  # Gap Up
+      BMB1 & MB[,1])           # 1st candle is black marubozu, 2nd candle is white marubozu
+    BEARK <- eval(TSGAP[,2] &  # Gap Down
+      WMB1 & MB[,4])           # 1st candle is white marubozu, 2nd candle is black marubozu
+  } else if (ignoreShadows==TRUE) {
+    LCB <- CSPLongCandleBody(TS, n=n, threshold=threshold)
+    LWCB1 <- Lag(LCB[,1], k=1)
+    LBCB1 <- Lag(LCB[,2], k=1)
+    BULLK <- eval(TSGAP[,1] &  # Gap Up
+      LBCB1 & LCB[,1])         # 1st candle has long black candle body, 2nd has long white candle body
+    BEARK <- eval(TSGAP[,2] &  # Gap Down
+      LWCB1 & LCB[,2])         # 1st candle has long white candle body, 2nd has long black candle body    
+  } else {
+    stop("ignoreShadows must be either TRUE or FALSE")
+  }
+  result <- cbind (BULLK, BEARK)
+  colnames (result) <- (c("Bull.Kicking", "Bear.Kicking"))
+  return (result)
+}
\ No newline at end of file

Added: pkg/R/CSPThreeInside.R
===================================================================
--- pkg/R/CSPThreeInside.R	                        (rev 0)
+++ pkg/R/CSPThreeInside.R	2012-01-16 09:52:53 UTC (rev 5)
@@ -0,0 +1,19 @@
+CSPThreeInside <- function(TS) {
+  if (!is.OHLC(TS)) {
+    stop("Price series must contain Open, High, Low and Close.")
+  }
+  LAGTS2 <- Lag(Op(TS), k=2)   # first candle of formation
+  LAGTS1 <- LagOHLC(TS, k=1)   # second candle
+  LAGHARAMI <- CSPHarami(LAGTS1)
+  TIUP <- eval(LAGHARAMI[,1] & # bullish harami
+    Cl(TS)>Op(TS) &            # 3rd candle is white
+    Cl(TS)>Cl(LAGTS1) &        # close of 3rd candle greater than close of 2nd candle
+    Cl(TS)>LAGTS2)             # close of 3rd candle greater than open of 1st candle
+  TIDOWN <- eval(LAGHARAMI[,2] & # bearish harami
+    Cl(TS)<Op(TS) &            # 3rd candle is black
+    Cl(TS)<Cl(LAGTS1) &        # close of 3rd candle lower than close of 2nd candle
+    Cl(TS)<LAGTS2)             # close of 3rd candle lower than open of 1st candle
+  result <- cbind(TIUP, TIDOWN)
+  colnames(result) <- c("ThreeInsideUp", "ThreeInsideDown")
+  return(result)
+}
\ No newline at end of file

Added: pkg/R/CSPThreeOutside.R
===================================================================
--- pkg/R/CSPThreeOutside.R	                        (rev 0)
+++ pkg/R/CSPThreeOutside.R	2012-01-16 09:52:53 UTC (rev 5)
@@ -0,0 +1,16 @@
+CSPThreeOutside <- function(TS) {
+  if (!is.OC(TS)) {
+    stop("Price series must contain Open and Close.")
+  }
+  LAGTS1 <- LagOHLC(TS, k=1)      # second candle
+  LAGENGULFING <- CSPEngulfing(LAGTS1)
+  TOUP <- eval(LAGENGULFING[,1] & # bullish engulfing
+    Cl(TS)>Op(TS) &               # 3rd candle is white
+    Cl(TS)>Cl(LAGTS1))            # 3rd candle closes above 2nd candle
+  TODOWN <- eval(LAGENGULFING[,2] & # bearish engulfing
+    Cl(TS)<Op(TS) &               # 3rd candle is black
+    Cl(TS)<Cl(LAGTS1))            # 3rd candle closes below 2nd candle
+  result <- cbind(TOUP, TODOWN)
+  colnames(result) <- c("ThreeOutsideUp", "ThreeOutsideDown")
+  return(result)
+}
\ No newline at end of file

Modified: pkg/man/CSPDoji.Rd
===================================================================
--- pkg/man/CSPDoji.Rd	2012-01-15 12:25:12 UTC (rev 4)
+++ pkg/man/CSPDoji.Rd	2012-01-16 09:52:53 UTC (rev 5)
@@ -10,18 +10,23 @@
 }
 \details{
 Number of candle lines: \bold{1}\cr
-A Doji is formed when the open and the close are the same or very close. By default settings, a doji is identified when the body of the candle is smaller or equal 1/10 of its full lenght.
+A Doji is formed when the open and the close are the same or very close. By default settings, a Doji is identified when the body of the candle is smaller or equal 1/10 of its full lenght.\cr
+The bullish Dragonfly Doji pattern has got a long lower shadow, but no upper shadow. In opposition, the bearish Gravestone Doji has got a long upper shadow but no lower shadow. Dragonfly and Gravestone Doji can be reversal signs during down/uptrends.
 }
 \value{
-  A xts object containing the column:
+  A xts object containing the columns:
   \item{Doji}{TRUE if Doji pattern detected}
+  \item{DragonflyDoji}{TRUE if Dragonfly Doji pattern detected}
+  \item{GravestoneDoji}{TRUE if Gravestone Doji pattern detected}  
 }
 \author{Andreas Voellenklee}
 \references{
 The following site(s) were used to code/document this candlestick pattern:\cr
-  \url{http://www.onlinetradingconcepts.com/TechnicalAnalysis/Candlesticks/Doji.html}
+  \url{http://www.onlinetradingconcepts.com/TechnicalAnalysis/Candlesticks/Doji.html}\cr
+  \url{http://www.candlesticker.com/Bullish.asp}\cr
+  \url{http://www.candlesticker.com/Bearish.asp}
 }
-\note{}
+\note{Trend detection prior to the formation is not implemented yet}
 \seealso{}
 \examples{
 \dontrun{

Added: pkg/man/CSPInsideDay.Rd
===================================================================
--- pkg/man/CSPInsideDay.Rd	                        (rev 0)
+++ pkg/man/CSPInsideDay.Rd	2012-01-16 09:52:53 UTC (rev 5)
@@ -0,0 +1,40 @@
+\name{CSPInside}
+\alias{CSPInsideDay}
+\alias{CSPOutsideDay}
+\title{Inside / Outside Day}
+\description{Look for inside days and outside days in a OHLC price series}
+\usage{
+  CSPInsideDay(TS)
+  CSPOutsideDay(TS)
+}
+\arguments{
+  \item{TS}{xts Time Series containing OHLC prices}
+}
+\details{
+  Number of candle lines: \bold{2}\cr\cr
+  \emph{Inside Day:}\cr
+  In an inside day, the bar remains within the previous day's bar high and low.\cr\cr
+  \emph{Outside Day:}\cr
+  In an outside day, the bar's high is higher than the previous day's bar high and the low lower than the previous day's low.
+}
+\value{
+  A xts object containing the column:
+  \item{InsideDay}{TRUE if current candle is a inside day}
+  \item{OutsideDay}{TRUE if current candle is a outside day}  
+}
+\author{Andreas Voellenklee}
+\references{
+The following site(s) were used to code/document this indicator:\cr
+  \url{http://www.investopedia.com/terms/i/inside_day.asp#axzz1jWelu1cm}\cr
+  \url{http://www.investopedia.com/terms/o/outside-days.asp#axzz1jWelu1cm}
+}
+\note{}
+\seealso{}
+\examples{
+\dontrun{
+  getSymbols('YHOO',adjust=TRUE)
+  CSPInsideDay(YHOO)
+  CSPOutsideDay(YHOO)
+}
+}
+\keyword{}

Added: pkg/man/CSPKicking.Rd
===================================================================
--- pkg/man/CSPKicking.Rd	                        (rev 0)
+++ pkg/man/CSPKicking.Rd	2012-01-16 09:52:53 UTC (rev 5)
@@ -0,0 +1,54 @@
+\name{CSPKicking}
+\alias{CSPKicking}
+\alias{Kicking}
+\title{Kicking Candlestick Pattern}
+\description{Look for bullish/bearish Kicking Candlestick Patterns in a OHLC price series}
+\usage{
+  CSPKicking(TS, ignoreShadows=TRUE, n=20, threshold=1.5)
+}
+\arguments{
+  \item{TS}{xts Time Series containing OHLC prices}
+  \item{ignoreShadows}{if TRUE, only Open and Close Price are evaluated. Hi and Low are ignored.}
+  \item{n}{number of preceding candles to calculate median candle length}
+  \item{threshold}{minimum candle length in relation to the median candle length of \code{n} preceding candles}
+}
+\details{
+  Number of candle lines: \bold{2}\cr\cr
+  \emph{Bullish Kicking Pattern:}\cr
+  The Bullish Kicking Pattern is a White Marubozu following a Black Marubozu. After the Black Marubozu, market gaps higher on the opening and it opens with a gap above the prior session’s opening thus forming a White Marubozu. This pattern is filtered with the option \code{ignoreShadows=FALSE}, and occurs very scarcely.\cr
+  A less strict filter rule is when \code{ignoreShadows=TRUE}. In this case, the pattern is detected when a long black candle body follows a long white candle body, and the open of the first candle is lower than the open of the second candle.\cr\cr
+  \emph{Bearish Kicking Pattern:}\cr
+  Opposite of Bullish Kicking Pattern.
+}
+\value{
+  A xts object containing the columns:
+  \item{Bull.Kicking}{TRUE if Bullish Kicking pattern detected}
+  \item{Bear.Kicking}{TRUE if Bearish Kicking pattern detected}
+}
+\author{Andreas Voellenklee}
+\references{
+The following site(s) were used to code/document this indicator:\cr
+  \url{http://www.candlesticker.com/Bullish.asp}\cr
+  \url{http://www.candlesticker.com/Bearish.asp}
+}
+\note{
+  Unlike most other candlestick patterns, the previous market direction is not important for this pattern.
+}
+\seealso{
+  \code{\link{CSPLongCandleBody}}
+  \code{\link{CSPMarubozu}}
+  \code{\link{CSPGap}}
+}
+\examples{
+\dontrun{
+  getSymbols('YHOO',adjust=TRUE)
+  
+  # look for Kicking Pattern right out of the textbook
+  # they occur only once in a blue moon
+  CSPKicking(YHOO, ignoreShadows=FALSE)
+  
+  # use less strict filter rules
+  CSPKicking(YHOO)
+}
+}
+\keyword{}

Modified: pkg/man/CSPNLongWhiteCandles.Rd
===================================================================
--- pkg/man/CSPNLongWhiteCandles.Rd	2012-01-15 12:25:12 UTC (rev 4)
+++ pkg/man/CSPNLongWhiteCandles.Rd	2012-01-16 09:52:53 UTC (rev 5)
@@ -37,8 +37,8 @@
 \examples{
 \dontrun{
   getSymbols('YHOO',adjust=TRUE)
-  CSPNLongWhiteCandle(YHOO)
-  CSPNLongBlackCandle(YHOO, N=3)  
+  CSPNLongWhiteCandles(YHOO)
+  CSPNLongBlackCandles(YHOO, N=3)  
   CSPNLongWhiteCandleBodies(YHOO)
   CSPNLongBlackCandleBodies(YHOO, N=4, n=50, threshold=1.2)
 }

Added: pkg/man/CSPThreeInside.Rd
===================================================================
--- pkg/man/CSPThreeInside.Rd	                        (rev 0)
+++ pkg/man/CSPThreeInside.Rd	2012-01-16 09:52:53 UTC (rev 5)
@@ -0,0 +1,41 @@
+\name{CSPThreeInside}
+\alias{CSPThreeInside}
+\alias{ThreeInsideUp}
+\alias{ThreeInsideDown}
+\title{Three Inside Up/Down Candlestick Pattern}
+\description{Look for Three Inside Up/Down Pattern in a OHLC price series.}
+\usage{
+  CSPThreeInside(TS)
+}
+\arguments{
+  \item{TS}{xts Time Series containing Open, High, Low and Close Prices}
+}
+\details{
+  Number of candle lines: \bold{3}\cr\cr
+  \emph{Three Inside Up:}\cr
+The market is in downtrend. The first two days of this pattern is the Bullish Harami Pattern, and the third day confirms the reversal suggested by the Bullish Harami Pattern, since it is a white candlestick closing with a new high for the last three days.\cr\cr
+  \emph{Three Inside Down:}\cr
+The market is in uptrend. The first two days of this pattern is the Bearish Harami Pattern, and the third day confirms the reversal suggested by the Bearish Harami Pattern, since it is a black candlestick closing with a new low for the last three days. 
+}
+\value{
+  A xts object containing the columns:
+  \item{ThreeInsideUp}{TRUE if Three Inside Up pattern detected}
+  \item{ThreeInsideDown}{TRUE if Three Inside Down pattern detected}
+}
+\author{Andreas Voellenklee}
+\references{
+The following site(s) were used to code/document this candlestick pattern:\cr
+  \url{http://www.candlesticker.com/Bullish.asp}\cr
+  \url{http://www.candlesticker.com/Bearish.asp}
+}
+\note{Trend detection prior to the formation is not implemented yet}
+\seealso{
+  \code{\link{CSPHarami}}
+  \code{\link{CSPThreeOutside}}
+}
+\examples{
+\dontrun{
+  getSymbols('YHOO',adjust=TRUE)
+  CSPThreeInside(YHOO)
+}
+}

Added: pkg/man/CSPThreeOutside.Rd
===================================================================
--- pkg/man/CSPThreeOutside.Rd	                        (rev 0)
+++ pkg/man/CSPThreeOutside.Rd	2012-01-16 09:52:53 UTC (rev 5)
@@ -0,0 +1,41 @@
+\name{CSPThreeOutside}
+\alias{CSPThreeOutside}
+\alias{ThreeOutsideUp}
+\alias{ThreeOutsideDown}
+\title{Three Outside Up/Down Candlestick Pattern}
+\description{Look for Three Outside Up/Down Pattern in a Open/Close price series.}
+\usage{
+  CSPThreeOutside(TS)
+}
+\arguments{
+  \item{TS}{xts Time Series containing Open and Close Prices}
+}
+\details{
+  Number of candle lines: \bold{3}\cr\cr
+  \emph{Three Outside Up:}\cr
+The market is in downtrend. The first two days of this pattern is the Bullish Engulfing Pattern, and the third day confirms the reversal suggested by the Bullish Engulfing Pattern, since it is a white candlestick closing with a new high for the last three days.\cr\cr
+  \emph{Three Outside Down:}\cr
+The market is in uptrend. The first two days of this pattern is the Bearish Engulfing Pattern, and the third day confirms the reversal suggested by the Bearish Engulfing Pattern, since it is a black candlestick closing with a new low for the last three days. 
+}
+\value{
+  A xts object containing the columns:
+  \item{ThreeOutsideUp}{TRUE if Three Outside Up pattern detected}
+  \item{ThreeOutsideDown}{TRUE if Three Outside Down pattern detected}
+}
+\author{Andreas Voellenklee}
+\references{
+The following site(s) were used to code/document this candlestick pattern:\cr
+  \url{http://www.candlesticker.com/Bullish.asp}\cr
+  \url{http://www.candlesticker.com/Bearish.asp}
+}
+\note{Trend detection prior to the formation is not implemented yet}
+\seealso{
+  \code{\link{CSPEngulfing}}
+  \code{\link{CSPThreeInside}}
+}
+\examples{
+\dontrun{
+  getSymbols('YHOO',adjust=TRUE)
+  CSPThreeOutside(YHOO)
+}
+}



More information about the Candlesticks-commits mailing list