% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ta_CCI.R
\name{commodity_channel_index}
\alias{commodity_channel_index}
\alias{CCI}
\title{Commodity Channel Index}
\usage{
commodity_channel_index(x, cols, n = 14, na.bridge = FALSE, ...)
}
\arguments{
\item{x}{An OHLC-V series coercible to \link{data.frame}.}

\item{cols}{(\link{formula}). An optional \code{3}-variable \link{formula} selecting columns from \code{x} via \link{model.frame}.
Defaults to \code{~high + low + close}.}

\item{n}{(\link{integer}). Lookback period (window size). A positive \link{integer}
of \link{length} 1.}

\item{na.bridge}{(\link{logical}). A \link{logical} of \link{length} 1. \link{FALSE} by
default. When \link{FALSE}, input \code{NA}s propagate through the TA-Lib C
routine (most indicators will fill the remaining output with
\code{NA}). When \link{TRUE}, input \code{NA} rows are stripped before
computation and re-inserted at the original positions in the
output, causing the indicator to treat non-consecutive non-\code{NA}
observations as if they were adjacent — see the \strong{Handling of
\code{NA} values} section above for the consequences.}

\item{...}{Additional parameters passed into \link{model.frame}.}
}
\value{
An object of same \link{class} and \link{length} of \code{x}:

\describe{
\item{CCI}{\link{double}}
}
}
\description{
\code{commodity_channel_index()} is a generic S3 function that preserves
the input \link{class}: \link{data.frame} in, \link{data.frame} out; \link{matrix} in,
\link{matrix} out.
\subsection{Handling of \code{NA} values}{

Every indicator always emits \strong{leading \code{NA}s} for the initial
lookback period - positions where there is not yet enough data to
produce a result. This is separate from how \code{NA}s already present
in the input are handled, which is controlled by the \code{na.bridge}
argument:

\describe{
\item{\code{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
\code{NA} in the input typically propagates forward and \strong{poisons
every subsequent value} - it is common for one missing
observation to produce an output that is entirely \code{NA} from that
position onward. This mode is the right choice when you want to
\emph{see} the missing data in the output rather than silently
compute around it.}
\item{\code{na.bridge = TRUE}}{\code{NA} rows 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 with \code{NA} inserted at every position the input
had \code{NA}. Output length always matches input length, so the
result can be joined back to the source \code{data.frame} by row.

\strong{Consequence to understand before enabling:} bridging causes
the indicator to treat non-consecutive observations as
consecutive. A 14-period RSI with \code{na.bridge = TRUE} over 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 as \code{NA}) the output is
correctly aligned \emph{by position} but economically meaningless
across the gap. Inspect gap structure with \code{which(is.na(x))}
before enabling on low-quality time series.}
}
}
}
\examples{
## load Bitcoin (BTC)
## series
data(BTC, package = "talib")

## calculate the indicator
## for Bitcoin (BTC)
output <- talib::commodity_channel_index(BTC)

## display the results
utils::tail(output)

## 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::commodity_channel_index
 )
}
}
\seealso{
Other Momentum Indicator:
\code{\link[=absolute_price_oscillator]{absolute_price_oscillator()}},
\code{\link[=aroon]{aroon()}},
\code{\link[=aroon_oscillator]{aroon_oscillator()}},
\code{\link[=average_directional_movement_index]{average_directional_movement_index()}},
\code{\link[=average_directional_movement_index_rating]{average_directional_movement_index_rating()}},
\code{\link[=balance_of_power]{balance_of_power()}},
\code{\link[=chande_momentum_oscillator]{chande_momentum_oscillator()}},
\code{\link[=directional_movement_index]{directional_movement_index()}},
\code{\link[=extended_moving_average_convergence_divergence]{extended_moving_average_convergence_divergence()}},
\code{\link[=fast_stochastic]{fast_stochastic()}},
\code{\link[=fixed_moving_average_convergence_divergence]{fixed_moving_average_convergence_divergence()}},
\code{\link[=intraday_movement_index]{intraday_movement_index()}},
\code{\link[=minus_directional_indicator]{minus_directional_indicator()}},
\code{\link[=minus_directional_movement]{minus_directional_movement()}},
\code{\link[=momentum]{momentum()}},
\code{\link[=money_flow_index]{money_flow_index()}},
\code{\link[=moving_average_convergence_divergence]{moving_average_convergence_divergence()}},
\code{\link[=percentage_price_oscillator]{percentage_price_oscillator()}},
\code{\link[=plus_directional_indicator]{plus_directional_indicator()}},
\code{\link[=plus_directional_movement]{plus_directional_movement()}},
\code{\link[=rate_of_change]{rate_of_change()}},
\code{\link[=ratio_of_change]{ratio_of_change()}},
\code{\link[=relative_strength_index]{relative_strength_index()}},
\code{\link[=stochastic]{stochastic()}},
\code{\link[=stochastic_relative_strength_index]{stochastic_relative_strength_index()}},
\code{\link[=triple_exponential_average]{triple_exponential_average()}},
\code{\link[=ultimate_oscillator]{ultimate_oscillator()}},
\code{\link[=williams_oscillator]{williams_oscillator()}}
}
\author{
Serkan Korkmaz
}
\concept{Momentum Indicator}
\concept{algorithmic trading}
\concept{finance}
\concept{technical analysis}
\concept{trading}
