Description Usage Arguments Details Value Author(s) See Also Examples
View source: R/TrendDetectionSMA.R
Uses the SMA of n periods to determine whether a price series is in uptrend or downtrend
1  | 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16  | ## 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)
 | 
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.