1

How to add series with dyCandlestick. The data has columns "timestamp", "open", "high", "low", "close", "volume", "mean_value", "ma_20", "ma_50". Following code gives me a right candlestick chart.

  library(tidyverse)
  dt <- read_csv("https://raw.githubusercontent.com/amandeepfj/RawData/master/top_rows.csv")

  dt.dy <- xts::xts(x = dt[, c("open", "high", "low", "close")], 
                    order.by = as.POSIXct(dt$timestamp))

  dygraph(dt.dy) %>%
    dyCandlestick() %>% 
    dyRangeSelector()

I want to show ma_20 & ma_50 in the same dygraph. I tried to pipe(%>%) dySeries, but it does not work.

Aman J
  • 1,825
  • 1
  • 16
  • 30

1 Answers1

0

You can combine the moving average series in the graph data: dt.dy.

library(dygraphs)
dt <-read_csv("https://raw.githubusercontent.com/amandeepfj/RawData/master/top_rows.csv")
dt.dy <- xts::xts(x = dt[, c("open", "high", "low", "close", "ma_20", "ma_50")], order.by = as.POSIXct(dt$timestamp))
dygraph(dt.dy) %>% dyCandlestick() %>% dyRangeSelector()
Garima Gulati
  • 43
  • 1
  • 7
  • dySeries() works only if dt.dy has that series. I would recommend you to take a look at some examples related to this package. You can check this [link]("https://rstudio.github.io/dygraphs/") – Garima Gulati Dec 22 '20 at 07:55
  • Also, the calculation for moving average seems to be wrong. – Garima Gulati Dec 22 '20 at 07:56