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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jan 20 15:42:00 CET 2012


Author: wotuzu17
Date: 2012-01-20 15:42:00 +0100 (Fri, 20 Jan 2012)
New Revision: 7

Added:
   pkg/R/CSPThreeMethods.R
   pkg/man/CSPThreeMethods.Rd
Modified:
   pkg/DESCRIPTION
   pkg/NAMESPACE
Log:
added CSPThreeMethods

Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION	2012-01-19 11:14:49 UTC (rev 6)
+++ pkg/DESCRIPTION	2012-01-20 14:42:00 UTC (rev 7)
@@ -1,8 +1,8 @@
 Package: candlesticks
 Type: Package
 Title: Candlestick Pattern Recognition
-Version: 0.1-6
-Date: 2012-01-19
+Version: 0.1-7
+Date: 2012-01-20
 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-19 11:14:49 UTC (rev 6)
+++ pkg/NAMESPACE	2012-01-20 14:42:00 UTC (rev 7)
@@ -24,6 +24,7 @@
 export(CSPTasukiGap)
 export(CSPThreeBlackCrows)
 export(CSPThreeInside)
+export(CSPThreeMethods)
 export(CSPThreeOutside)
 export(CSPThreeWhiteSoldiers)
 # lag functions

Added: pkg/R/CSPThreeMethods.R
===================================================================
--- pkg/R/CSPThreeMethods.R	                        (rev 0)
+++ pkg/R/CSPThreeMethods.R	2012-01-20 14:42:00 UTC (rev 7)
@@ -0,0 +1,33 @@
+CSPThreeMethods <- function (TS, n=20, threshold=1.5) {
+  if (!is.OHLC(TS)) {
+    stop("Price series must contain Open, High, Low and Close.")
+  }
+  LAG4TS <- LagOHLC(TS, k=4)
+  LAG3TS <- LagOC(TS, k=3)
+  LAG1TS <- LagOC(TS, k=1)
+  MAXOP <- lag(runMax(Op(TS), n=3), k=1) # max open for middle 3 candles
+  MAXCL <- lag(runMax(Cl(TS), n=3), k=1) # max close for middle 3 candles 
+  MINOP <- lag(runMin(Op(TS), n=3), k=1) # min open for middle 3 candles
+  MINCL <- lag(runMin(Cl(TS), n=3), k=1) # min close for middle 3 candles
+  LC4 <- CSPLongCandleBody(LAG4TS, n=n, threshold=threshold)
+  LC0 <- CSPLongCandleBody(TS, n=n, threshold=threshold)
+  RTM <- eval (LC4[,1] &          # 1st candle: long white candle body
+    Op(LAG3TS) > Cl(LAG3TS) &     # 2nd candle: black candle
+    Op(LAG1TS) > Cl(LAG1TS) &     # 4th candle: black candle
+    MAXOP < Hi(LAG4TS) & MAXOP > Lo(LAG4TS) & # candle bodies 2,3,4 within range of 1st candle
+    MAXCL < Hi(LAG4TS) & MAXCL > Lo(LAG4TS) &
+    MINOP < Hi(LAG4TS) & MINOP > Lo(LAG4TS) &
+    MINCL < Hi(LAG4TS) & MINCL > Lo(LAG4TS) &
+    LC0[,1] & Cl(TS) > Cl(LAG4TS)) # 5th candle: long white candle body that closes higher than 1st candle
+  FTM <- eval (LC4[,2] &           # 1st candle: long black candle body
+    Op(LAG3TS) < Cl(LAG3TS) &      # 2nd candle: white candle
+    Op(LAG1TS) < Cl(LAG1TS) &      # 4th candle: white candle
+    MAXOP < Hi(LAG4TS) & MAXOP > Lo(LAG4TS) & # candle bodies 2,3,4 within range of 1st candle
+    MAXCL < Hi(LAG4TS) & MAXCL > Lo(LAG4TS) &
+    MINOP < Hi(LAG4TS) & MINOP > Lo(LAG4TS) &
+    MINCL < Hi(LAG4TS) & MINCL > Lo(LAG4TS) &
+    LC0[,2] & Cl(TS) < Cl(LAG4TS)) # 5th candle: long black candle  body that closes lower than 1st candle
+  result <- cbind (RTM, FTM)
+  colnames (result) <- c("RisingThreeMethods", "FallingThreeMethods")
+  return (result)
+}
\ No newline at end of file

Added: pkg/man/CSPThreeMethods.Rd
===================================================================
--- pkg/man/CSPThreeMethods.Rd	                        (rev 0)
+++ pkg/man/CSPThreeMethods.Rd	2012-01-20 14:42:00 UTC (rev 7)
@@ -0,0 +1,44 @@
+\name{CSPThreeMethods}
+\alias{CSPThreeMethods}
+\alias{RisingThreeMethods}
+\alias{FallingThreeMethods}
+\title{Rising/Falling Three Methods Candlestick Pattern}
+\description{Look for Rising/Falling Three Methods Pattern in a OHLC price series}
+\usage{CSPThreeMethods(TS, n=20, threshold=1.5)}
+\arguments{
+  \item{TS}{xts Time Series containing OHLC prices}  
+  \item{n}{number of preceding candles to calculate median candle body length}
+  \item{threshold}{minimum/maximum candle body length in relation to the median candle length of \code{n} preceding candle bodies}
+}
+\details{
+Number of candle lines: \bold{5}\cr\cr
+\emph{Rising Three Methods:}\cr
+Prior trend: \bold{up}\cr
+The formation starts with a long white candle body. The following three bars are smaller candles that open/close within the high/low span of the first candle. The last candle is a again a long white candle that closes above the close price of the first candle.
+\cr\cr
+\emph{Falling Three Methods:}\cr
+Prior trend: \bold{down}\cr
+The formation starts with a long black candle body. The following three bars are smaller candles that open/close within the high/low span of the first candle. The last candle is a again a long black candle that closes below the close price of the first candle.
+}
+\value{
+  A xts object containing the columns:
+  \item{RisingThreeMethods}{TRUE if Rising Three Methods pattern detected}
+  \item{FallingThreeMethods}{TRUE if Falling Three Methods pattern detected}
+}
+\author{Andreas Voellenklee}
+\references{
+The following site(s) were used to code/document this candlestick pattern:\cr
+  \url{http://www.investopedia.com/terms/r/rising-three-methods.asp}\cr
+  \url{http://www.investopedia.com/terms/f/falling-three-methods.asp}\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{}
+\examples{
+\dontrun{
+  getSymbols('URZ',adjust=TRUE)
+  CSPThreeMethods(URZ)
+}
+}
+\keyword{}



More information about the Candlesticks-commits mailing list