Create an ichimoku object containing values for all components of the Ichimoku Kinko Hyo cloud chart. The object encapsulates a date-time index, OHLC pricing data, candle direction, the cloud lines Tenkan-sen, Kijun-sen, Senkou span A, Senkou span B and Chikou span, as well as values for the cloud top and cloud base.

ichimoku(x, ticker, periods = c(9L, 26L, 52L), keep.data, ...)

# S3 method for ichimoku
ichimoku(x, ticker, periods = c(9L, 26L, 52L), keep.data, ...)

# S3 method for xts
ichimoku(x, ticker, periods = c(9L, 26L, 52L), keep.data, ...)

# S3 method for data.frame
ichimoku(x, ticker, periods = c(9L, 26L, 52L), keep.data, ...)

# S3 method for matrix
ichimoku(x, ticker, periods = c(9L, 26L, 52L), keep.data, ...)

# S3 method for default
ichimoku(x, ticker, periods = c(9L, 26L, 52L), keep.data, ...)

Arguments

x

a data.frame or other compatible object, which includes xts, data.table, tibble, and matrix.

ticker

(optional) specify a ticker to identify the instrument, otherwise this is set to the name of the input object.

periods

[default c(9L, 26L, 52L)] a vector defining the length of periods used for the cloud. This parameter shoud not normally be modified as using other values would be invalid in the context of traditional ichimoku analysis.

keep.data

(optional) set to TRUE to retain additional data present in the input object as additional columns and/or attributes.

...

additional arguments, for instance 'holidays', passed along to tradingDays for calculating the future cloud on daily data.

Value

An ichimoku object with S3 classes of 'ichimoku', 'xts' and 'zoo'.

Details

Calling an ichimoku object automatically invokes its print method, which by default produces a printout of the data to the console as well as a plot of the cloud chart to the graphical device.

For further options, use plot() on the returned ichimoku object to pass further arguments for customising the chart. Use iplot() for interactive charting.

Where an ichimoku object is passed to ichimoku(), the ichimoku object is re-calculated using the OHLC pricing data contained within.

Ichimoku Object Specification

Index:

  • index(object): date-time index [POSIXct]

Columns [numeric]:

  • object$open: opening price

  • $high: high price

  • $low: low price

  • $close: closing price

  • $cd: candle direction (-1 = down, 0 = flat, 1 = up)

  • $tenkan: Tenkan-sen

  • $kijun: Kijun-sen

  • $senkouA: Senkou span A

  • $senkouB: Senkou span B

  • $chikou: Chikou span

  • $cloudT: cloud Top (max of senkouA, senkouB)

  • $cloudB: cloud Base (min of senkouA, senkouB)

Attributes:

  • attributes(object)$periods: parameters used to calculate the cloud [integer vector of length 3]

  • $periodicity: periodicity of the data in seconds [numeric]

  • $ticker: instrument identifier [character]

Further Details

ichimoku() requires OHLC (or else HLC) price data as input to calculate the cloud chart values.

If only single series price data is supplied, a pseudo OHLC series is generated and a pseudo cloud chart is returned.

A faster technical utility version of this function is available in .ichimoku for use when the data is already in the required format.

Please refer to the reference vignette by calling: vignette("reference", package = "ichimoku")

Examples

TKR <- sample_ohlc_data

cloud <- ichimoku(TKR)
cloud
#> # ichimoku object: use more() to display more rows, look() to inspect
#> #   attributes
#>    index                open  high   low close    cd tenkan kijun senkouA
#>    <dttm>              <dbl> <dbl> <dbl> <dbl> <dbl>  <dbl> <dbl>   <dbl>
#>  1 2020-01-02 00:00:00 123   123.1 122.5 122.7    -1   NA      NA      NA
#>  2 2020-01-03 00:00:00 122.7 122.8 122.6 122.8     1   NA      NA      NA
#>  3 2020-01-06 00:00:00 122.8 123.4 122.4 123.3     1   NA      NA      NA
#>  4 2020-01-07 00:00:00 123.3 124.3 123.3 124.1     1   NA      NA      NA
#>  5 2020-01-08 00:00:00 124.1 124.8 124   124.8     1   NA      NA      NA
#>  6 2020-01-09 00:00:00 124.8 125.4 124.5 125.3     1   NA      NA      NA
#>  7 2020-01-10 00:00:00 125.3 125.3 124.8 125.2    -1   NA      NA      NA
#>  8 2020-01-13 00:00:00 125.2 125.3 125.1 125.2     0   NA      NA      NA
#>  9 2020-01-14 00:00:00 125.2 125.2 124.3 124.4    -1  123.9    NA      NA
#> 10 2020-01-15 00:00:00 124.4 124.5 123.7 123.9    -1  123.9    NA      NA
#> # … with 271 more rows, and 4 more variables: senkouB <dbl>, chikou <dbl>,
#> #   cloudT <dbl>, cloudB <dbl>


kumo <- ichimoku(TKR, ticker = "TKR Co.", periods = c(9, 26, 52), keep.data = TRUE)
summary(kumo)
#> ichimoku object with dimensions (281, 13) 
#> 
#>             Max: 2020-07-13 23:00:00 [139.7]
#> Start: 2020-01-02 00:00:00 [123]   End: 2020-12-24 00:00:00 [136]
#>             Min: 2020-05-12 23:00:00 [119.1]
#> 
#> Cloud periods: 9 26 52 
#> Periodicity: 1 days 
#> Ticker: TKR Co. 
print(kumo, plot = FALSE, n = 20)
#> # ichimoku object: use more() to display more rows, look() to inspect
#> #   attributes
#>    index                open  high   low close    cd tenkan kijun senkouA
#>    <dttm>              <dbl> <dbl> <dbl> <dbl> <dbl>  <dbl> <dbl>   <dbl>
#>  1 2020-01-02 00:00:00 123   123.1 122.5 122.7    -1  NA       NA      NA
#>  2 2020-01-03 00:00:00 122.7 122.8 122.6 122.8     1  NA       NA      NA
#>  3 2020-01-06 00:00:00 122.8 123.4 122.4 123.3     1  NA       NA      NA
#>  4 2020-01-07 00:00:00 123.3 124.3 123.3 124.1     1  NA       NA      NA
#>  5 2020-01-08 00:00:00 124.1 124.8 124   124.8     1  NA       NA      NA
#>  6 2020-01-09 00:00:00 124.8 125.4 124.5 125.3     1  NA       NA      NA
#>  7 2020-01-10 00:00:00 125.3 125.3 124.8 125.2    -1  NA       NA      NA
#>  8 2020-01-13 00:00:00 125.2 125.3 125.1 125.2     0  NA       NA      NA
#>  9 2020-01-14 00:00:00 125.2 125.2 124.3 124.4    -1 123.9     NA      NA
#> 10 2020-01-15 00:00:00 124.4 124.5 123.7 123.9    -1 123.9     NA      NA
#> 11 2020-01-16 00:00:00 123.9 124.4 123.8 124.2     1 123.9     NA      NA
#> 12 2020-01-17 00:00:00 124.2 124.3 123   123.5    -1 124.2     NA      NA
#> 13 2020-01-20 00:00:00 123.5 123.8 123.1 123.2    -1 124.2     NA      NA
#> 14 2020-01-21 00:00:00 123.6 123.6 123.4 123.6     0 124.2     NA      NA
#> 15 2020-01-22 00:00:00 123.5 124   123.3 123.5     0 124.15    NA      NA
#> 16 2020-01-23 00:00:00 123.5 124.5 123.3 124.3     1 124.15    NA      NA
#> 17 2020-01-24 00:00:00 124.3 124.4 124   124.2    -1 124.1     NA      NA
#> 18 2020-01-27 00:00:00 124.2 124.2 122.7 123      -1 123.6     NA      NA
#> 19 2020-01-28 00:00:00 123   123.6 122.7 123.1     1 123.6     NA      NA
#> 20 2020-01-29 00:00:00 123.1 123.3 123.1 123.2     1 123.6     NA      NA
#> # … with 261 more rows, and 5 more variables: senkouB <dbl>, chikou <dbl>,
#> #   cloudT <dbl>, cloudB <dbl>, volume <dbl>
plot(kumo, theme = "solarized", type = "bar", custom = "volume")