quantmod icon indicating copy to clipboard operation
quantmod copied to clipboard

addVo() and pretty scale

Open jsramseyer opened this issue 6 years ago • 2 comments

Description

Chartseries adds (by default) a second volume chart, equivalent to "addVo ()"

The volume chart scale is represented in a friendly way (x thousand, x one hundred thousand, etc.)

When we add the Volume average to this graph, it is plotted without friendly scaling (x unit) and is outside the plot area.

Expected behavior

he expected behavior is to represent "SMA (Vo (VALE3.SA), n = 20)" on the same scale as the variable that created the second graph, in this case "Vo ()".

Minimal, reproducible example

# incorrect behavior of function Vo() in second graph
fim <- Sys.Date()
inicio <- Sys.Date() - 730

getSymbols("VALE3.SA", from= inicio, to = fim)
chartSeries(VALE3.SA, theme = "white", TA='addEMA(n=21); addVo(); addTA(SMA(Vo(VALE3.SA), n=20), on=2)', subset = 'last 6 months')

# correct behavior, add function in second graph, but not Vo() function
chartSeries(VALE3.SA, theme = "white", TA= 'addEMA(n=21,col="red"); addOBV(); addTA(EMA(OBV(Cl(VALE3.SA), Vo(VALE3.SA)), n=10), on =2)', subset = 'last 6 months')



Session Info

[Insert your sessionInfo() output]

jsramseyer avatar Sep 19 '19 22:09 jsramseyer

You may get the desired result with the newer charting functions. Try this:

d <- na.omit(getSymbols("VALE3.SA", from=Sys.Date()-300, to=Sys.Date(), auto.assign=FALSE))
rm(g)  # remove graphics chob in case it exists already
g <- chart_Series(d, TA='add_EMA(n=21, on=1); add_Vo()', name='vale3.sa')
g <- add_TA(SMA(Vo(d), n=20), col='blue', on=2)
plot(g)

helgasoft avatar Feb 01 '20 06:02 helgasoft

I agree that this is a bug in chartSeries() and/or addTA(), but I'm not sure it's worth the effort to try and fix. Especially when chart_Series() works.

joshuaulrich avatar Feb 23 '20 13:02 joshuaulrich