TrendDetectionSMA {candlesticks}R Documentation

Current Trend Detection using Simple Moving Average

Description

Uses the SMA of n periods to determine whether a price series is in uptrend or downtrend

Usage

TrendDetectionSMA(TS, n=20)

Arguments

TS

xts Time Series containing OHLC prices

n

number of periods for the SMA to average over

Details

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.

Value

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

Author(s)

Andreas Voellenklee

See Also

TrendDetectionChannel

Examples

## 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)

[Package candlesticks version 0.2-9 Index]