R: Get the QuantmodSeries and AddTA diagrams so you don’t show the last value

When using chartSeries by default, it also displays the last value in the upper left corner of the chart. Is there any way to prevent this?

When adding a new TA with addTA, you can avoid the last value on the graph by setting the argument legend = "", but only if you create a new graph for TA. If TA is on a previously plotted chart, it will show the last value regardless of what you entered into the legend argument.

getSymbols ("AAPL", src = "google")
chartSeries(AAPL)

What can I use here to prevent it from printing the last value on the chart?

addTA(EMA(Cl(AAPL)), on = 1, legend = "")

It still prints the last value in the upper left corner of the graph. The strange part is that it does not do this if you are plotting on a new plot like this:

addTA(EMA(Cl(AAPL)), legend = "")

, -, , ?

+4
1

(, ). , , , addTA.

addTA, add_TA chart_Series, , ( quantmod). , add_TA. .

add_TA 56-60 :

text.exp, :

# this is inside add_TA:
if (is.na(on)) {
    plot_object$add_frame(ylim = c(0, 1), asp = 0.15)
    plot_object$next_frame()
    text.exp <- expression(text(x = c(1, 1 + strwidth(name)), 
                                y = 0.3, labels = c(name, round(last(xdata[xsubset]), 
                                                                5)), col = c(1, col), adj = c(0, 0), cex = 0.9, 
                                offset = 0, pos = 4))
    plot_object$add(text.exp, env = c(lenv, plot_object$Env), 

:

if (is.na(on)) {
    plot_object$add_frame(ylim = c(0, 1), asp = 0.15)
    plot_object$next_frame()
    text.exp <- expression(text(x = c(strwidth(name)), # <- affects label on the subchart
                            y = 0.3, labels = name, col = c(col), adj = c(0), cex = 0.9, 
                            offset = 1, pos = 4))
     plot_object$add(text.exp, env = c(lenv, plot_object$Env), 
                expr = TRUE)

... , say add_TA.mine:

add_TA.mine <- function (x, order = NULL, on = NA, legend = "auto", yaxis = list(NULL, 
                                                                  NULL), col = 1, taType = NULL, ...) 
{
  lenv <- new.env()
  lenv$name <- deparse(substitute(x))
  lenv$plot_ta <- function(x, ta, on, taType, col = col, ...) {
    xdata <- x$Env$xdata 
    ....
     [all the code for the rest of the function with modifications]....

           }
    }
    plot_object
}

library(quantmod)
getSymbols("AAPL")

environment(add_TA.mine) <- environment(get("add_TA", envir = asNamespace("quantmod")))
assignInNamespace(x = "add_TA", value = add_TA.mine, ns = "quantmod")


chart_Series(AAPL, subset = "2017")
add_TA(RSI(Cl(AAPL)))
quantmod:::add_TA(RSI(Cl(AAPL)))

, :

enter image description here

( addTA (, chartSeries, )

add_TA, quantmod ( ). , quandmod.

+4

Source: https://habr.com/ru/post/1688313/


All Articles