[R-SIG-Finance] addLines in Quantmod

Marc Delvaux mdelvaux at gmail.com
Thu Jul 8 20:13:45 CEST 2010

Adding color is easy, addLines() use col like lines() itself, so you
can change the code like this

> plotBrackets <- function () {
>        require(quantmod)
>        getSymbols('AAPL')
>        chartSeries(AAPL["2009::"],theme='white',
> TA='addLines(h=c(82,103,135), col=c("red","blue","green"))' )
> }

but adding legends is more difficult and exceed my quantmod knowledge
at this time.  I did try to use text() but without success.  Obviously
quantmod itself inserts text at the top in the graph area, so this
must be possible.

On Thu, Jul 8, 2010 at 9:42 AM, Andres Petrocelli <cordura21 at gmail.com> wrote:
> MMarc and Joshua: thanks for your replies.
> Your suggestions work. The issue with the plot(addlines(...)) form is that,
> at least in my case, it prints 2 charts to the pdf file. The first one is
> just the candlestick chart, the second one contains the added line.
> Marc's second code (using the TA parameter) produces just one chart, and is
> what I am after.
> What I want to do is to chart a bracket order, so I extended the code to
> this:
> plotBrackets <- function () {
>        require(quantmod)
>        getSymbols('AAPL')
>        chartSeries(AAPL["2009::"],theme='white',
> TA='addLines(h=c(82,103,135))' )
> }
> Where 103 is the entry, 82 the stop and 135 the target.
> I wonder if you can help me to distinguish in some way between the 3 lines,
> either by coloring them or (much better) adding text labels.
> Thanks in advance. Andrés
>        [[alternative HTML version deleted]]
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch 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