## load library
library(cryptoQuotes)As an experimental feature {cryptoQuotes} has a
variety of chart-functions built on top of {plotly} and {TTR} to visualize
cryptocurrency market data and trading indicators interactively.
Throughout this article we will analyze Bitcoin on the hourly chart
called by the get_quotes()-function,
## Get the
## SPOT price of 
## Bitcoin on the hourly
BTC <- get_quote(
  ticker   = "BTCUSD",
  source   = "kraken",
  futures  = FALSE,
  interval = "1h",
  from     = Sys.Date() - 7
)Price charts
There are two main price charts. The Japanese candlestick chart,
kline(), and the basic OHLC chart, ohlc(),
charts. A chart has to be wrapped in the
chart()-function.
Charting indicators
All the charts supports various indicators such as the relative
strenght index (rsi())-, Moving Average
Convergence Divergence (macd())- and various
moving average indicators. These can be passed into their
respective arguments as follows,
Charting events
All charts supports passing event_data, which are any
type of data.frame, that can be plotted on the chart. Below
is an example of plotting the crossing of the MA,
## Calculate moving averages
## SMA(7) and SMA(10)
BTC$short_SMA <- TTR::SMA(
  x = BTC$close,
  n = 7
)
BTC$long_SMA <- TTR::SMA(
  x = BTC$close,
  n = 21
)
## Determine the cross
## from below
BTC$cross <- as.numeric(
  lag(BTC$short_SMA) < BTC$long_SMA &
    BTC$short_SMA > BTC$long_SMA 
)Based on the cross indicator, the BTC pair
can now be subset, and processed accordingly.
## create event data
## and store it as a data.rfrae
event_data <- subset(
  BTC,
  cross == 1
)
# 1.1) Extract the index
# from the event data
index <- zoo::index(
  event_data
)
# 1.2) Convert the coredata
# into a data.frame
event_data <- as.data.frame(
  zoo::coredata(event_data)
)
# 1.3) Add the index into the data.frame
# case insensitive
event_data$index <- index
# 1.4) add events to the data.
# here we use Buys and Sells.
event_data$event <- 'Bull Cross'
event_data$color <- 'darkgray'Finally, the crosses can be plotted using the chart() as
follows,
