[Candlesticks-commits] r14 - in pkg: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Apr 11 15:53:39 CEST 2012
Author: wotuzu17
Date: 2012-04-11 15:53:38 +0200 (Wed, 11 Apr 2012)
New Revision: 14
Modified:
pkg/DESCRIPTION
pkg/R/CSPDarkCloudCover.R
pkg/R/CSPPiercingPattern.R
pkg/man/CSPDarkCloudCover.Rd
pkg/man/CSPPiercingPattern.Rd
Log:
re-worked detection rules for Piercing Pattern and Dark Cloud Cover
Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION 2012-04-10 20:34:40 UTC (rev 13)
+++ pkg/DESCRIPTION 2012-04-11 13:53:38 UTC (rev 14)
@@ -1,8 +1,8 @@
Package: candlesticks
Type: Package
Title: Candlestick Pattern Recognition
-Version: 0.1-10
-Date: 2012-04-08
+Version: 0.1-11
+Date: 2012-04-11
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/R/CSPDarkCloudCover.R
===================================================================
--- pkg/R/CSPDarkCloudCover.R 2012-04-10 20:34:40 UTC (rev 13)
+++ pkg/R/CSPDarkCloudCover.R 2012-04-11 13:53:38 UTC (rev 14)
@@ -1,12 +1,14 @@
-CSPDarkCloudCover <- function(TS) {
+CSPDarkCloudCover <- function(TS, n=20, minbodysizeMedian=1) {
if (!is.OC(TS)) {
stop("Price series must contain Open and Close.")
}
LAGTS <- LagOC(TS, k=1)
+ LongCandleBody <- CSPLongCandleBody(LAGTS, n=n, threshold=minbodysizeMedian)
DarkCloudCover <- reclass(eval (
- Cl(LAGTS)>Op(LAGTS) & Op(TS)>Cl(TS)
- & Op(TS)>Cl(LAGTS) & (Op(LAGTS)+Cl(LAGTS))/2 > Cl(TS)
- & Cl(TS)>Op(LAGTS) ), TS)
+ LongCandleBody[,"LongWhiteCandleBody"] & # first candle is white and longer than median of past n candles
+ Op(TS)>Cl(LAGTS) & # second candle opens higher than close of 1st candle
+ (Op(LAGTS)+Cl(LAGTS))/2 >= Cl(TS) &# second candle closes at or below half of 1st candles' body
+ Cl(TS)>Op(LAGTS) ), TS) # close of second candle is higher than open of 1st candle
colnames(DarkCloudCover) <- c("DarkCloudCover")
xtsAttributes(DarkCloudCover) <- list(bars=2)
return(DarkCloudCover)
Modified: pkg/R/CSPPiercingPattern.R
===================================================================
--- pkg/R/CSPPiercingPattern.R 2012-04-10 20:34:40 UTC (rev 13)
+++ pkg/R/CSPPiercingPattern.R 2012-04-11 13:53:38 UTC (rev 14)
@@ -1,12 +1,15 @@
-CSPPiercingPattern <- function(TS) {
+CSPPiercingPattern <- function(TS, n=20, minbodysizeMedian=1) {
if (!is.OC(TS)) {
stop("Price series must contain Open and Close.")
}
LAGTS <- LagOC(TS, k=1)
+ LongCandleBody <- CSPLongCandleBody(LAGTS, n=n, threshold=minbodysizeMedian)
+
PiercingPattern <- reclass(eval (
- Op(LAGTS)>Cl(LAGTS) & Cl(TS)>Op(TS)
- & Cl(LAGTS)>Op(TS) & Cl(TS)>(Op(LAGTS)+Cl(LAGTS))/2
- & Op(LAGTS)>Cl(TS) ), TS)
+ LongCandleBody[,"LongBlackCandleBody"] & # first candle is black and longer than median of past n candles
+ Op(TS)<Cl(LAGTS) & # second candle opens lower than close of 1st candle
+ Cl(TS)>=(Op(LAGTS)+Cl(LAGTS))/2 & # second candle closes at or higher than half of 1st candles' body
+ Cl(TS)<Op(LAGTS) ), TS) # close of second candle is lower than open of 1st candle
colnames(PiercingPattern) <- c("PiercingPattern")
xtsAttributes(PiercingPattern) <- list(bars=2)
return(PiercingPattern)
Modified: pkg/man/CSPDarkCloudCover.Rd
===================================================================
--- pkg/man/CSPDarkCloudCover.Rd 2012-04-10 20:34:40 UTC (rev 13)
+++ pkg/man/CSPDarkCloudCover.Rd 2012-04-11 13:53:38 UTC (rev 14)
@@ -3,12 +3,15 @@
\alias{DarkCloudCover}
\title{Dark Cloud Cover Candlestick Pattern}
\description{Look for Dark Cloud Covers in a Open/Close price series}
-\usage{CSPDarkCloudCover(TS)}
+\usage{CSPDarkCloudCover(TS, n=20, minbodysizeMedian=1)}
\arguments{
\item{TS}{xts Time Series containing Open and Close prices}
+ \item{n}{number of preceding candles to calculate median candle body length}
+ \item{minbodysizeMedian}{Minimum body length relative to the median of the past \code{n} body sizes}
}
\details{
-A white candlestick is followed by a gap higher during the next day while the market is in uptrend. The day ends up as a black candlestick, which closes more than halfway into the prior black candlestick's real body.
+Number of candle lines: \bold{2}\cr\cr
+A long white candlestick is followed by a gap higher during the next day while the market is in uptrend. The day ends up as a black candlestick, which closes more than halfway into the prior black candlestick's real body.
}
\value{
A xts object containing the column:
@@ -20,12 +23,18 @@
\url{http://www.candlesticker.com/Bearish.asp}\cr
\url{http://www.onlinetradingconcepts.com/TechnicalAnalysis/Candlesticks/DarkCloudCover.html}
}
-\note{Trend detection prior to the formation is not implemented yet}
+\note{The function filters patterns that look like dark cloud covers, without considering the current trend direction. If only pattern in uptrends should be filtered, a external trend detection function must be used. See examples.}
\seealso{The counterpart of this pattern is \code{\link{PiercingPattern}}}
\examples{
\dontrun{
getSymbols('YHOO',adjust=TRUE)
CSPDarkCloudCover(YHOO)
+
+ # filter dark cloud covers that occur in uptrends.
+ # the lag of 2 periods of the time series for trend detection
+ # ensures that the uptrend is active \emph{before} the
+ # dark cloud cover occurs.
+ eval(CSPDarkCloudCover(YHOO) & TrendDetectionChannel(lag(YHOO,k=2))[,"UpTrend"])
}
}
\keyword{}
Modified: pkg/man/CSPPiercingPattern.Rd
===================================================================
--- pkg/man/CSPPiercingPattern.Rd 2012-04-10 20:34:40 UTC (rev 13)
+++ pkg/man/CSPPiercingPattern.Rd 2012-04-11 13:53:38 UTC (rev 14)
@@ -3,12 +3,15 @@
\alias{PiercingPattern}
\title{Piercing Candlestick Pattern}
\description{Look for Piercing Patterns in a Open/Close price series}
-\usage{CSPPiercingPattern(TS)}
+\usage{CSPPiercingPattern(TS, n=20, minbodysizeMedian=1)}
\arguments{
\item{TS}{xts Time Series containing Open and Close Prices}
+ \item{n}{number of preceding candles to calculate median candle body length}
+ \item{minbodysizeMedian}{Minimum body length relative to the median of the past \code{n} body sizes}
}
\details{
-A black candlestick is followed by a gap lower during the next day while the market is in downtrend. The day ends up as a white candlestick, which closes more than halfway into the prior black candlestick's real body.
+Number of candle lines: \bold{2}\cr\cr
+A long black candlestick is followed by a gap lower during the next day while the market is in downtrend. The day ends up as a white candlestick, which closes more than halfway into the prior black candlestick's real body.
}
\value{
A xts object containing the column:
@@ -20,12 +23,18 @@
\url{http://www.candlesticker.com/Bullish.asp}\cr
\url{http://www.onlinetradingconcepts.com/TechnicalAnalysis/Candlesticks/PiercingPattern.html}
}
-\note{Trend detection prior to the formation is not implemented yet}
+\note{The function filters patterns that look like piercing patterns, without considering the current trend direction. If only pattern in downtrends should be filtered, a external trend detection function must be used. See examples.}
\seealso{The counterpart of this pattern is \code{\link{DarkCloudCover}}}
\examples{
\dontrun{
getSymbols('YHOO',adjust=TRUE)
CSPPiercingPattern(YHOO)
+
+ # filter piercing patterns that occur in downtrends.
+ # the lag of 2 periods of the time series for trend detection
+ # ensures that the uptrend is active \emph{before} the
+ # dark cloud cover occurs.
+ eval(CSPPiercingPattern(YHOO) & TrendDetectionChannel(lag(YHOO,k=2))[,"DownTrend"])
}
}
\keyword{}
More information about the Candlesticks-commits
mailing list