R/TrendDetectionSMA.R

Defines functions TrendDetectionSMA

Documented in TrendDetectionSMA

TrendDetectionSMA<- function(TS, n=20) {
  if (!has.Cl(TS)) {
    stop("Price series must contain Close prices")
  }
  Close <- Cl(TS)
  CloseToSMA <- Close/SMA(Close,n=n)
  UpTrend <- CloseToSMA[,1] > 1
  NoTrend <- CloseToSMA[,1] == 1
  DownTrend <- CloseToSMA[,1] < 1
  Trend <- UpTrend+ DownTrend*(-1)
  result <- cbind(UpTrend, NoTrend, DownTrend, Trend)
  colnames(result) <- c("UpTrend", "NoTrend", "DownTrend", "Trend")
  return(result)
}

Try the candlesticks package in your browser

Any scripts or data that you put into this service are public.

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