TrendDetectionSMA: Current Trend Detection using Simple Moving Average

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/TrendDetectionSMA.R

Description

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

Usage

1

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

 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)

candlesticks documentation built on Feb. 2, 2020, 3:01 a.m.