ichimoku_kinko_hyo() is a generic S3 function that preserves
the input class: data.frame in, data.frame out; matrix in,
matrix out; xts in, xts out. Other inputs coercible to
data.frame (e.g. zoo) are computed on the coerced data.frame.
Handling of NA values
Every indicator always emits leading NAs for the initial
lookback period - positions where there is not yet enough data to
produce a result. This is separate from how NAs already present
in the input are handled, which is controlled by the na.bridge
argument:
na.bridge = FALSE(default)The input is passed to the underlying TA-Lib C routine as-is. Because most indicators smooth across time (EMA, RSI, MACD, Bollinger Bands, ...), a single
NAin the input typically propagates forward and poisons every subsequent value - it is common for one missing observation to produce an output that is entirelyNAfrom that position onward. This mode is the right choice when you want to see the missing data in the output rather than silently compute around it.na.bridge = TRUENArows are stripped from the input before the C routine runs; the indicator is computed on the resulting dense series; results are then re-expanded to the original length withNAinserted at every position the input hadNA. Output length always matches input length, so the result can be joined back to the sourcedata.frameby row.Consequence to understand before enabling: bridging causes the indicator to treat non-consecutive observations as consecutive. A 14-period RSI with
na.bridge = TRUEover a series containing a month-long gap will compute using 14 observations that span several real-world months as if they were 14 adjacent trading days. For sparse missing values (e.g. a single missing tick) this is harmless; for clustered gaps (e.g. a delisted period, a weekend encoded asNA) the output is correctly aligned by position but economically meaningless across the gap. Inspect gap structure withwhich(is.na(x))before enabling on low-quality time series.
Usage
ichimoku_kinko_hyo(
x,
cols,
tenkanPeriod = 9,
kijunPeriod = 26,
senkouBPeriod = 52,
na.bridge = FALSE,
...
)Arguments
- x
An OHLC-V series coercible to data.frame.
- cols
(formula). An optional
2-variable formula selecting columns fromxvia model.frame. Forxtsinput each formula variable is matched against the column names directly - exact matches first, then quantmod-style suffix matches (closematchesTICKER.Close), case-insensitively - and columns are consumed in formula order. Defaults to~high + low.- tenkanPeriod
(integer). Period of the conversion line. Defaults to
9.- kijunPeriod
(integer). Period of the base line, and the forward shift of the two spans. Defaults to
26.- senkouBPeriod
(integer). Period of the second leading span. Defaults to
52.- na.bridge
(logical). A logical of length 1. FALSE by default. When FALSE, input
NAs propagate through the TA-Lib C routine (most indicators will fill the remaining output withNA). When TRUE, inputNArows are stripped before computation and re-inserted at the original positions in the output, causing the indicator to treat non-consecutive non-NAobservations as if they were adjacent — see the Handling ofNAvalues section above for the consequences.- ...
Additional parameters passed into model.frame. Unused for
xtsinput (a warning is emitted when supplied).
Details
On a chart the two leading spans, and the cloud between them, are
drawn kijunPeriod bars ahead of the bar that computed them. The
x-axis is not extended, so the part of the cloud beyond the last
bar is not drawn. The returned values themselves are not shifted.
See also
Other Overlap Studies:
acceleration_bands(),
arnaud_legoux_moving_average(),
bollinger_bands(),
chande_kroll_stop(),
donchian_channels(),
double_exponential_moving_average(),
exponential_moving_average(),
extended_parabolic_stop_and_reverse(),
fractal_adaptive_moving_average(),
hull_moving_average(),
kaufman_adaptive_moving_average(),
keltner_channels(),
mcginley_dynamic(),
mesa_adaptive_moving_average(),
midpoint_period(),
midpoint_price(),
parabolic_stop_and_reverse(),
simple_moving_average(),
swiss_army_knife_butterworth_filter(),
swiss_army_knife_gaussian_filter(),
t3_exponential_moving_average(),
trendline(),
triangular_moving_average(),
triple_exponential_moving_average(),
variable_index_dynamic_moving_average(),
variable_moving_average_period(),
volume_weighted_moving_average(),
weighted_moving_average(),
wilder_smoothed_moving_average(),
zero_lag_exponential_moving_average()
Examples
## load Bitcoin (BTC)
## series
data(BTC, package = "talib")
## calculate the indicator
## for Bitcoin (BTC)
output <- talib::ichimoku_kinko_hyo(BTC)
## display the results
utils::tail(output)
#> TenkanSen KijunSen SenkouSpanA SenkouSpanB
#> 2024-12-26 01:00:00 99324.18 99931.55 99627.86 87901.50
#> 2024-12-27 01:00:00 97441.49 99931.55 98686.52 88048.49
#> 2024-12-28 01:00:00 96004.49 99931.55 97968.02 91421.55
#> 2024-12-29 01:00:00 96128.88 99931.55 98030.21 92008.16
#> 2024-12-30 01:00:00 95594.99 99836.55 97715.77 92061.55
#> 2024-12-31 01:00:00 95594.99 99836.55 97715.77 92454.67
## visualize the indicator
## with talib::chart()
##
## see ?talib::chart or ?talib::indicator
## for more details
{
## chart OHLC-V
## series with talib::chart()
talib::chart(BTC)
## chart indicator
## with default values
talib::indicator(
talib::ichimoku_kinko_hyo
)
}