[R-SIG-Finance] How to add net lines to quantmod charts

Samo Pahor samo.pahor at gmail.com
Fri Aug 26 13:43:01 CEST 2011


Hi,

I have worked some more on how to reproduce the attached chart and the best
I was able to come up in a day with is this:
require(quantmod)

getSymbols("SPY")

lines.SPY <- (Hi(SPY) + Lo(SPY))/2
names(lines.SPY) <- c("lines")
lines.SPY$BuySell <- ifelse(lag(lines.SPY$lines) > lines.SPY$lines, 1, -1)

chartSeries(SPY, subset="2011-08::", theme=chartTheme('white',
up.col='blue', dn.col='red'))
addTA(lines.SPY$lines[lines.SPY$BuySell == -1,], type='p', col='darkred',
pch="_", on=1, cex = 2.5)
addTA(lines.SPY$lines[lines.SPY$BuySell == 1,], type='p', col='green4',
pch="_", on=1, cex = 2.5)

But I still can not add text on top of the line (value of lines.SPY$lines).
Well, what I have produced is not actually not a line, but a symbol. I would
like a line.

My question actually goes in to direction how to use quantmod chart object
and on this current chart object add a line at specific position of specific
length, thickness and color and just a little above that line how to add
text with specific color...

I also do not know how to actually get from xts objects to x and y
coordiantes on quantmod chart object.

Any help/ideas/code examples appreciated.

Best regards,
Samo.

2011/8/25 Samo Pahor <samo.pahor at gmail.com>

> Hi,
>
> Is it possible to produce attached chart with so called "net lines" (short
> line with number on top in different colors) using quantmod?
>
> The Idea is that there would be a data frame with datetime, value, type
> (each row represents one "net line" with its numeric value and whether it is
> a sell (color in red) or buy(color in green)). And this lines with data in
> dataframe would then be overlayed on quantmod chart.
>
> Is something like this possible with quantmod? I would appreciate any
> ideas/examples of code...
>
> Best regards,
> Samo.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20110826/19da3834/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: netlines.png
Type: image/png
Size: 49448 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20110826/19da3834/attachment.png>


More information about the R-SIG-Finance mailing list