<div class="gmail_extra">Here is a function add_stoch that works, although it is heavy coding given that one is adding a subframe which is a single line plot. Also, there should be no need to call add_stoch more than once for efficiency. Finally, the add_xxx() collection of routines presumes that the underlying function xxx() returns a single series, which is why I need to create the inner function stoch1. </div>
<div class="gmail_extra"><br></div><div class="gmail_extra">Surely there must be a simpler approach. I attach the code (I do not know whether attachments work.)</div><div class="gmail_extra"><br></div><div class="gmail_extra">
<br></div><div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_extra">add_stoch = function (nFastK = 10, nFastD=3, nSlowD=3, maType, bounded=T, smooth=1, on = 1, ...) </div><div class="gmail_extra">
{</div><div class="gmail_extra"><span class="Apple-tab-span" style="white-space:pre"> </span>stoch1 = function (HLC, nFastK = 10, nFastD=3, nSlowD=3, maType, bounded=T, smooth=1, ...)</div><div class="gmail_extra"><span class="Apple-tab-span" style="white-space:pre"> </span>{</div>
<div class="gmail_extra"><span class="Apple-tab-span" style="white-space:pre"> </span>return(stoch(HLC, nFastK, nFastD, nSlowD, maType, bounded, smooth, ...)['2012'][,2])</div><div class="gmail_extra"><span class="Apple-tab-span" style="white-space:pre"> </span>}</div>
<div class="gmail_extra"><br></div><div class="gmail_extra"> lenv <- new.env()</div><div class="gmail_extra"> lenv$add_stoch <- function(x, nFastK = 10, nFastD=3, nSlowD=3, maType=SMA, bounded=T, smooth=1, ...) {</div>
<div class="gmail_extra"> xdata <- x$Env$xdata</div><div class="gmail_extra"> xsubset <- x$Env$xsubset</div><div class="gmail_extra"> sto <- stoch1(Cl(xdata), nFastK=nFastK,nFastD=nFastD,nSlowD=nSlowD,maType=SMA, bounded=bounded, smooth=smooth)[xsubset]</div>
<div class="gmail_extra"> lines(1:NROW(xdata[xsubset]), sto, ...)</div><div class="gmail_extra"> }</div><div class="gmail_extra"> mapply(function(name, value) {</div><div class="gmail_extra"> assign(name, value, envir = lenv)</div>
<div class="gmail_extra"> }, names(list(nFastK=nFastK,nFastD=nFastD,nSlowD=nSlowD,maType=SMA, bounded=bounded, smooth=smooth, ...)), list(nFastK=nFastK,nFastD=nFastD,nSlowD=nSlowD,maType=SMA, bounded=bounded, smooth=smooth, ...))</div>
<div class="gmail_extra"> exp <- parse(text = gsub("list", "add_stoch", as.expression(substitute(list(x = current.chob(), </div><div class="gmail_extra"> nFastK=nFastK,nFastD=nFastD,nSlowD=nSlowD,maType=SMA, bounded=bounded, smooth=smooth, ...)))), srcfile = NULL)</div>
<div class="gmail_extra"> plot_object <- current.chob()</div><div class="gmail_extra"> lenv$xdata <- stoch1(Cl(plot_object$Env$xdata),nFastK=nFastK,nFastD=nFastD,nSlowD=nSlowD,maType=SMA, bounded=bounded, smooth=smooth)</div>
<div class="gmail_extra"> plot_object$set_frame(sign(on) * abs(on) + 1L)</div><div class="gmail_extra"> plot_object$add(exp, env = c(lenv, plot_object$Env), expr = TRUE)</div><div class="gmail_extra"> plot_object</div>
<div class="gmail_extra">}</div><div class="gmail_extra"><br></div><div><br></div></div>