Skip to contents

The cryptoQuotes library uses plotly to visualize the quotes interactively.

Note: As per 2023-12-23 the charting is still in its experimental phase.

There are two main price charts. The Japanese candlestick charts, klines, and basic OHLC charts. A chart has to be wrapped in the chart function.

OHLC chart

## simple bar-chart
## without indicators
chart(
  chart = ohlc(
    ATOMUSDT
  )
)

Candlestick chart

## simple kline chart
## without indicators
chart(
  chart = kline(
    ATOMUSDT
  )
)

Common indicators

All charts supports various indicators such as RSI and Bollinger Bands. All indicators starts with addIndicator, and can be used with he magrittr pipe operator.

RSI and Bollinger Bands

## simple kline chart
## without indicators
chart(
  chart = kline(ATOMUSDT) %>% 
    addRSI() %>% 
    addBBands()
)

MACD and Volume

## simple kline chart
## without indicators
chart(
  chart = kline(ATOMUSDT) %>%
    addMACD() %>% 
    addVolume()
)

Charting events

Various events in the financial markets does, undoubtedly, have an impact on the prices. For traders relying on technical analysis one important event is when the short simple moving average (SMA), crosses the long SMA.

## Calculate moving averages
## SMA(7) and SMA(10)
ATOMUSDT$short_SMA <- TTR::SMA(
  x = ATOMUSDT$Close,
  n = 7,
)

ATOMUSDT$long_SMA <- TTR::SMA(
  x = ATOMUSDT$Close,
  n = 21,
)

## Determine the cross
## from below
ATOMUSDT$cross <- as.numeric(
  lag(ATOMUSDT$short_SMA) < ATOMUSDT$long_SMA &
    ATOMUSDT$short_SMA > ATOMUSDT$long_SMA 
)

Based on the cross indicator, the ATOMUSDT pair can now be subset, and processed accordingly.

NOTE: The library supports all kinds of data.frames, including data.table and tibbles.

## create event data
## and store it as a data.rfrae
event_data <- subset(
  ATOMUSDT,
  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 and addEvents functions, like below,

chart(
  chart = kline(quote = ATOMUSDT)  %>% 
    addBBands()                    %>%
    addMA(FUN = TTR::SMA, n = 7)   %>%
    addMA(FUN = TTR::SMA, n = 21)  %>% 
    addEvents(event = event_data)
)