1

I am new to R and quantmod. I created a new indicator which I like to add to a plot with addTA. But the scale of the indicator should be logarithmic. First I tried (with RSI as an example)

> chartSeries ...
> rsi <- RSI(Cl(...))
> addTA(rsi,log.scale=T)
Warning message:
In plot.xy(xy.coords(x, y), type = type, ...) :
  "log.scale" is not a graphical parameter

Then I copied addTA from source (packageVersion('quantmod') 0.4.12) and tried some dirty modifications:

--- addTA       
+++ addTA.test  
@@ -1 +1,2 @@
+addTA.test <-
 function (ta, order = NULL, on = NA, legend = "auto", yrange = NULL, 
@@ -11,3 +12,3 @@
     else {
-        lchob <- get.current.chob()
+        lchob <- quantmod:::get.current.chob()
         chobTA <- new("chobTA")
@@ -41,3 +42,4 @@
             order = order, legend = legend, pars = list(list(...)), 
-            time.scale = lchob@time.scale)
+            time.scale = lchob@time.scale, log.scale = T)
+       chobTA@log.scale <- T
         return(chobTA)

Which also results in an error

> source ...
> addTA.test(rsi)
Error in (function (cl, name, valueClass)  : 
  'log.scale' is not a slot in class "chobTA"

How can I draw an indicator with logarithmic scale?

FXQuantTrader
  • 6,821
  • 3
  • 36
  • 67
tom9
  • 25
  • 2

1 Answers1

0

You could simply use the log function before passing into addTA

library(quantmod)
x <- getSymbols("AAPL", auto.assign=FALSE)
rsi <- RSI(Cl(x))

chartSeries(x, subset = "2017")
addTA(log(rsi))

# Newer, cleaner charts alternative:
chart_Series(x, subset = "2017")
add_TA(log(rsi))
add_TA(rsi)
FXQuantTrader
  • 6,821
  • 3
  • 36
  • 67
  • Thank you for this code snippet, which might provide some limited, immediate help. A [proper explanation would greatly improve its long-term value](//meta.stackexchange.com/q/114762/350567) by showing *why* this is a good solution to the problem, and would make it more useful to future readers with other, similar questions. Please [edit] your answer to add some explanation, including the assumptions you've made. – iBug Jan 31 '18 at 07:21
  • iBug, FXQuantTrader provided a workaround. This is done by modifying the data instead of modifying the type of scale (which is what I'm looking for). The result is a correct graph but a wrong scale. Eg for indicator values below 1 the scale will be negative. Can indicators be drawn with log.scale at all? – tom9 Jan 31 '18 at 13:05
  • @tom9 The warning tells you there is no `log.scale` that `addTA` uses as a passthrough parameter via `...`. So, no, not via a parameter to `addTA` or `add_TA`. i.e. you could pass in `lOg.sCale2 = T`, or `abcd1234 = T` as you'd get a similar warning (but no error)... what you've done doesn't do anything. Modifying the data is probably your best bet to generate a log scale for your indicator. – FXQuantTrader Jan 31 '18 at 13:25