Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with quantmod add_TA and chart_Series - lines and text disappear after next add_TA is called

I am using new chart_Series and add_TA quite a lot. It works very well for me and I find it very useful.

I am trying to add a few things (horizontal lines and some text) on a graph. Here problems start to occur. After horizontal lines and text are drawn correctly they disappear if I call subsequent add_TA... Please see the example code below which reproduces the problem:

library(quantmod)

getSymbols("SPY")

dev.new()
chart_Series(SPY)
add_TA(ADX(HLC(SPY))$ADX)
abline(h=15, col="red")
abline(h=35, col="green")
text(10, 7, "Text and horizontal lines disappear after next add_TA is called",
  col="blue", cex=0.8, adj = c(0,0))
# run the code up to this point (including text(...
# see how horizontal lines drawn with abline and text is displayed correctly
# now run the last line by adding additional TA and you will see that lines
# and text disappears
add_TA(DVI(Cl(SPY))$dvi)

Is this intended behavior?

EDIT: How to make this work (as per Joshua comment below: redrawing also line and text when plot object (chob) is being redrawn)?

like image 471
Samo Avatar asked Dec 26 '11 23:12

Samo


1 Answers

The add_*** functions add information to the plot object (chob) and re-draw it. abline and text do not add their information to the plot object; they just draw to the device, so their contributions are lost when you re-draw the plot object.

like image 160
Joshua Ulrich Avatar answered Oct 13 '22 03:10

Joshua Ulrich