title: How to create a technical indicator in quantmod package
body: <p>I'm a newbie to R and I am facing some problems with the creation of a technical indicator. More specifically, I want to create an indicator, <code>Fibonacci</code>, which will be added to the <code>chartSeries</code> and will consist of 5 horizontal lines. The data I am working with are the closing  prices of a stock. So the graph I want to create will have one horizontal line in the point of the max closing price, one horizontal line in the point of the min closing price and three horizontal lines between the previous two. The code I wrote in order to take the five values of a time series of closing prices of a stock is the following:</p>
  
  <pre><code>Fibonacci &lt;- function(x) {
  x &lt;- try.xts(x, error = as.matrix)
  n &lt;- nrow(x)
  min &lt;- runMin(x,n=n)
  max &lt;- runMax(x,n=n)
  high &lt;- 0.62*(max-min) + min
  middle &lt;- 0.5*(max-min) + min
  low &lt;- 0.38*(max-min) + min
  res &lt;-cbind(na.spline(min),na.spline(max),na.spline(high),
              na.spline(middle),na.spline(low))
  colnames(res)&lt;- c("min","max","high","middle","low") 
  reclass (res, x)
  }
  </code></pre>
  
  <p>I also wrote the following code in order to add the technical indicator to the existing <code>chartSeries</code> plot of <code>quantmod</code> package :</p>
  
  <pre><code>addFibonacci&lt;- function(col = "red",overlay = TRUE){
  stopifnot("package:TTR" %in% search() || require("TTR", quietly = TRUE))
  lchob &lt;- quantmod:::get.current.chob() 
  x &lt;- as.matrix(lchob@xdata)
  chobTA &lt;- new("chobTA")
  chobTA@new &lt;- !overlay
  if (!is.OHLC(x)) 
      stop("Fibonacci requires HL series")
  else {
  fibon &lt;- Fibonacci(Cl(x))
  }
  chobTA@TA.values &lt;- fibon[lchob@xsubset]
  chobTA@call &lt;- match.call()
  chobTA@on &lt;- 1
  chobTA@params &lt;- list(xrange = lchob@xrange, colors = lchob@colors, 
      color.vol = lchob@color.vol, multi.col = lchob@multi.col, 
      spacing = lchob@spacing, width = lchob@width, bp = lchob@bp, 
      x.labels = lchob@x.labels, time.scale = lchob@time.scale, 
      col = col)
  if (is.null(sys.call(-1))) {
      TA &lt;- lchob@passed.args$TA
      lchob@passed.args$TA &lt;- c(TA, chobTA)
      lchob@windows &lt;- lchob@windows + ifelse(chobTA@new, 1, 
          0)
      chartSeries.chob &lt;- quantmod:::chartSeries.chob
      do.call(chartSeries.chob, list(lchob))
      invisible(chobTA)
  }
  else {
      return(chobTA)
  }
  }
  </code></pre>
  
  <p>The problem is that the indicator is not getting added to the chart and I am also getting the following error message:</p>
  
  <pre><code>Error in do.call(x@passed.args$TA[[j]]@name, list(x@passed.args$TA[[j]])) :
    'what' must be a character string or a function
  </code></pre>
  
  <p>Any ideas for what I am doing wrong?</p>