quantmod icon indicating copy to clipboard operation
quantmod copied to clipboard

Refactor addCLV to follow skeleton_TA structure

Open erichung0404 opened this issue 8 years ago • 0 comments

Refactor addCLV to use skeleton_TA structure. chartCLV function is given to create Close Location Value indicator based on skeleton_TA structure as following:

addTA <- function(arg, ...) {
  lenv <- new.env()
  lenv$chartTA <- function(x, arg, ...) {
    xdata <- x$Env$xdata
    xsubset <- x$Env$xsubset
    # special handling for arguments here

    ta <- TA(xdata, arg, ...)[xsubset]

    # draw indicators here

  }
  mapply(function(name, value) assign(name, value, lenv), names(list(arg = arg, ...)), list(arg = arg, ...))
  exp <- sub("list", "chartTA", as.expression(substitute(list(x = current.chob(), arg = arg, ...)), srcfile = NULL)
  exp <- c(exp, expression.to.add.legend)
  exp <- c(expression.to.add.background.and.horizontal.ticks, exp)
  lchob <- current.chob()
  x <- lchob$Env$xdata
  xsubset <- lchob$Env$xsubset
  ta <- TA(x, arg, ...)[xsubset]
  lchob$Env$ta <- ta
  lchob$add_frame(ylim, asp = 1, fixed = TRUE)
  lchob$next_frame()
  lchob$replot(exp, env = c(lenv, lchob$Env), expr = TRUE)
  lchob
}

erichung0404 avatar Aug 05 '16 08:08 erichung0404