R/DonchianChannel2.R

Defines functions DonchianChannel2

Documented in DonchianChannel2

# DonchianChannel function in TTR lacks a 1 period-lag of the result
# hence, this modified (corrected) version is used in package candlesticks
DonchianChannel2 <- function(HL, n = 10) {
    if (NCOL(HL) > 1 && (!has.Lo(HL) || !has.Hi(HL))) {
      stop("Price series must either contain High and Low, or be univariate.")
    }
    if (NCOL(HL) > 1) {
      hi <- Hi(HL)[, 1]
      lo <- Lo(HL)[, 1]
    } else hi <- lo <- HL
    high <- runMax(hi, n)
    low <- runMin(lo, n)
    mid <- (high + low)/2
    result <- stats::lag(cbind(high, mid, low))
    colnames(result) <- c("high", "mid", "low")
    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.