[R-SIG-Finance] Problems with chartSeries when called in a function
Joshua Ulrich
josh.m.ulrich at gmail.com
Sun Apr 1 01:48:49 CEST 2012
This question has been raised many times on-list. Search for
"chartSeries plot from function" on rseek.org and look at the results
on the "Support Lists" tab.
You need to wrap your addTA calls in plot(). The reason you get
addCCI is because it's being returned from the function.
test <- function(PAIR="USD/NZD"){
S <- getSymbols(PAIR, src="oanda", auto.assign=FALSE)
NZD.w <- to.weekly(S)
chartSeries(NZD.w)
po <- EMA(NZD.w)
plot(addTA(po))
plot(addCCI(n=14))
}
Best,
--
Joshua Ulrich | FOSS Trading: www.fosstrading.com
R/Finance 2012: Applied Finance with R
www.RinFinance.com
On Sat, Mar 31, 2012 at 6:35 PM, Worik Stanton <worik.stanton at gmail.com> wrote:
> Friends
>
> I have the following sequence of commands that work as expected....
>
> S <- getSymbols("USD/NZD", src="oanda", auto.assign=FALSE)
> NZD.w <- to.weekly(S)
> chartSeries(NZD.w)
> po <- EMA(NZD.w)
> addTA(po)
> addCCI(n=14)
>
> (I know I could use addEMA but I have some signal code that would be
> meaningless here in this context)
>
>
> I get a three part graph: The series as a candlestick chart and the two
> indicators each in a panel
>
> If I use a function...
>
>
> test <- function(PAIR="USD/NZD"){
>
> ## This function is different if called than if stepped through
> S <- getSymbols(PAIR, src="oanda", auto.assign=FALSE)
> NZD.w <- to.weekly(S)
> chartSeries(NZD.w)
> po <- EMA(NZD.w)
> addTA(po)
> addCCI(n=14)
> }
>
>
> and call test() I get a two part graph.
>
> Why is it different?
>
> cheers
> Worik
>
> --
> Foo!
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
More information about the R-SIG-Finance
mailing list