## -----------------------------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 7, fig.height = 5
)

## -----------------------------------------------------------------------------
library(ichimoku)

## -----------------------------------------------------------------------------
# # ichimoku can create clouds directly from OANDA data, for example:
# cloud <- ichimoku(oanda("USD_JPY"))

## -----------------------------------------------------------------------------
# # Using R 4.1's new pipe operator:
# oanda("USD_JPY") |> ichimoku() |> plot()
# # Or equally using the 'magrittr' pipe:
# oanda("USD_JPY") %>% ichimoku() %>% plot()

## -----------------------------------------------------------------------------
# Sample OHLC price data is assigned to data frame 'TKR':
TKR <- sample_ohlc_data
head(TKR)

## -----------------------------------------------------------------------------
cloud <- ichimoku(TKR)

print(cloud, plot = FALSE, width = 180)

## -----------------------------------------------------------------------------
str(cloud)

## -----------------------------------------------------------------------------
summary(cloud)

## -----------------------------------------------------------------------------
kumo <- ichimoku(TKR, keep.data = TRUE)

kumo[, "volume"]

## -----------------------------------------------------------------------------
# # Holidays can be specified directly via a vector of dates:
# ichimoku(TKR, holidays = c("2020-01-13", "2020-02-11", "2020-02-24"))
# 
# # Or via a functions that returns a vector of dates (e.g. from the 'timeDate' package):
# ichimoku(TKR, holidays = timeDate::holidayLONDON())
# ichimoku(TKR, holidays = timeDate::holidayNYSE())
# 
# # For a market that trades 24/7:
# ichimoku(TKR, holidays = NULL)
# 

## -----------------------------------------------------------------------------
index <- index(cloud)
core <- coredata(cloud)

cloud2 <- ichimoku(ichimoku(cbind(index, core), ticker = attr(cloud, "ticker")))
identical(cloud, cloud2)

## -----------------------------------------------------------------------------
plot(cloud, window = "2020-05/", ticker = "SYM (JSE)", subtitle = "Sample Data Series")

## -----------------------------------------------------------------------------
# c("#d9d9d9", "#d7d7d7", "#d1d1d1", "#737373", "#1f1f1f", "#b8b8b8", "#1a1a1a", "#1a1a1a", "#1a1a1a", "#ffffff", "#333333", "#1a1a1a")

## -----------------------------------------------------------------------------
# # To plot an R-type oscillator:
# plot(cloud, type = "r")

## -----------------------------------------------------------------------------
plot(cloud, window = "2020-04-01/2020-12-01", theme = "solarized", type = "s")

## -----------------------------------------------------------------------------
plot(kumo, window = "2020-04/2020-11", theme = "mono", type = "bar", custom = "volume")

## -----------------------------------------------------------------------------
# # For an interactive plot:
# iplot(cloud)

## -----------------------------------------------------------------------------
# # Write object to file:
# archive(object, "path/filename")
# # Leave second argument empty to choose file save location from a system dialog:
# archive(object, )

## -----------------------------------------------------------------------------
# # Read from file to object:
# object <- archive("path/filename")
# # Choose a file from an interactive system dialog:
# object <- archive()

