TrendDetectionSMA {candlesticks} | R Documentation |
Uses the SMA of n
periods to determine whether a price series is in uptrend or downtrend
TrendDetectionSMA(TS, n=20)
TS |
xts Time Series containing OHLC prices |
n |
number of periods for the SMA to average over |
This function assumes that a price series is in uptrend (downtrend) when a period's price closes above (below) the simple moving average of n
periods.
A xts object containing the columns:
UpTrend |
TRUE if uptrend detected (Close > SMA(n)) |
NoTrend |
TRUE if sideward trend detected (Close == SMA(n)) |
DownTrend |
TRUE if downtrend detected (Close < SMA(n)) |
Trend |
+1 for uptrend, 0 for sideward trend, -1 for downtrend |
Andreas Voellenklee
## Not run: getSymbols("YHOO", adjust=TRUE) # create chart of YAHOO chartSeries(YHOO, subset="last 1 year", TA=NULL) # visualize the result of trend detection in a indicator box addTA(TrendDetectionSMA(YHOO)[,4]) # filter YHOO for Hammer Candlestick Patterns that occur in downtrends Hammer <- CSPHammer(TS) & TrendDetectionSMA(TS)[,"DownTrend"] # how frequent are these hammers? colSums(Hammer, na.rm=TRUE) ## End(Not run)