% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/chart_indicator.R
\name{indicator}
\alias{indicator}
\title{Add Technical Indicators to a Chart}
\usage{
indicator(FUN, ...)
}
\arguments{
\item{FUN}{An indicator function or an indicator call. In single indicator
mode, pass the bare function (e.g., \code{RSI}); arguments for the indicator
go in \code{...}. In multi-indicator mode, pass a call with parentheses
(e.g., \code{RSI(n = 14)}); additional indicator calls go in \code{...}.}

\item{...}{In single indicator mode: arguments passed to \code{FUN} (e.g.,
\code{n = 14}, \code{data = BTC}). In multi-indicator mode: additional indicator
calls to merge onto the same panel (e.g., \code{RSI(n = 21)}, \code{MACD()}).}
}
\value{
A chart object whose class depends on the active backend:
\itemize{
\item \code{"plotly"} backend: a \code{plotly} object containing the
assembled multi-panel chart.
\item \code{"ggplot2"} backend: a \code{talib_chart} object (when
combined with \code{\link[=chart]{chart()}}) or a \code{gg} object (standalone).
}
}
\description{
\code{indicator()} attaches one or more technical indicators to an existing
\code{\link[=chart]{chart()}}, or renders an indicator as a standalone chart. Each indicator
is displayed in its own subchart panel below the main price chart.

If \code{\link[=chart]{chart()}} has not been called beforehand, \code{indicator()} creates a
standalone indicator chart — in this case, \code{data} must be provided
explicitly.

See \code{vignette(topic = "charting", package = "talib")} for a comprehensive
guide.
}
\details{
\code{indicator()} operates in two modes depending on how \code{FUN} is passed:
\subsection{Single Indicator Mode}{

Pass a bare function name (without parentheses) and its arguments via
\code{...}:

\if{html}{\out{<div class="sourceCode r">}}\preformatted{chart(BTC)
indicator(RSI, n = 14)
}\if{html}{\out{</div>}}
}

\subsection{Multi-Indicator Mode}{

Pass one or more indicator calls (with parentheses) to merge them onto
a single subchart panel:

\if{html}{\out{<div class="sourceCode r">}}\preformatted{chart(BTC)
indicator(RSI(n = 10), RSI(n = 14), RSI(n = 21))
}\if{html}{\out{</div>}}

Each indicator retains its own arguments. Different indicator types can
be freely combined on the same panel:

\if{html}{\out{<div class="sourceCode r">}}\preformatted{indicator(RSI(n = 14), MACD())
}\if{html}{\out{</div>}}

Multi-indicator mode requires an existing \code{\link[=chart]{chart()}} — it cannot be used
standalone.
}

\subsection{Standalone Mode}{

When no \code{\link[=chart]{chart()}} has been called, a standalone indicator chart is created.
The \code{data} argument is required in this case:

\if{html}{\out{<div class="sourceCode r">}}\preformatted{indicator(RSI, data = BTC, n = 14)
}\if{html}{\out{</div>}}

The chart title is automatically derived from the indicator function name,
converting \code{snake_case} to Title Case.
}

\subsection{Panel Layout}{

When subcharts are present, the main price panel occupies 70\% of the total
height by default (configurable via \code{options(talib.chart.main = ...)}), and
the remaining space is divided equally among subchart panels.
}
}
\examples{
## indicator charts with {talib}
data(BTC, package = "talib")

## standalone indicator chart
## (no prior chart() call needed)
talib::indicator(
  talib::RSI,
  data = BTC
)

## attach an indicator to a price chart
talib::chart(BTC)
talib::indicator(talib::RSI, n = 14)

## multiple indicators on the same panel
talib::chart(BTC)
talib::indicator(
  talib::RSI(n = 10),
  talib::RSI(n = 14),
  talib::RSI(n = 21)
)

## reset chart state
talib::chart()
}
\seealso{
\code{\link[=chart]{chart()}} to create the main price chart, \code{\link[=set_theme]{set_theme()}} to
customize chart colors.

Other Charting:
\code{\link[=chart]{chart()}},
\code{\link{chart_themes}},
\code{\link[=set_theme]{set_theme()}}
}
\author{
Serkan Korkmaz
}
\concept{Charting}
