indicator() attaches one or more technical indicators to an existing
chart(), or renders an indicator as a standalone chart. Each indicator
is displayed in its own subchart panel below the main price chart.
If chart() has not been called beforehand, indicator() creates a
standalone indicator chart — in this case, data must be provided
explicitly.
See vignette(topic = "charting", package = "talib") for a comprehensive
guide.
Arguments
- FUN
An indicator function or an indicator call. In single indicator mode, pass the bare function (e.g.,
RSI); arguments for the indicator go in.... In multi-indicator mode, pass a call with parentheses (e.g.,RSI(n = 14)); additional indicator calls go in....- ...
In single indicator mode: arguments passed to
FUN(e.g.,n = 14,data = BTC). In multi-indicator mode: additional indicator calls to merge onto the same panel (e.g.,RSI(n = 21),MACD()).
Value
A chart object whose class depends on the active backend:
"plotly"backend: aplotlyobject containing the assembled multi-panel chart."ggplot2"backend: atalib_chartobject (when combined withchart()) or aggobject (standalone).
Details
indicator() operates in two modes depending on how FUN is passed:
Multi-Indicator Mode
Pass one or more indicator calls (with parentheses) to merge them onto a single subchart panel:
Each indicator retains its own arguments. Different indicator types can be freely combined on the same panel:
Multi-indicator mode requires an existing chart() — it cannot be used
standalone.
See also
chart() to create the main price chart, ggplot2::set_theme() to
customize chart colors.
Other Charting:
chart(),
chart_themes,
set_theme()
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()
