Skip to contents

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.

Usage

indicator(FUN, ...)

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: a plotly object containing the assembled multi-panel chart.

  • "ggplot2" backend: a talib_chart object (when combined with chart()) or a gg object (standalone).

Details

indicator() operates in two modes depending on how FUN is passed:

Single Indicator Mode

Pass a bare function name (without parentheses) and its arguments via ...:

chart(BTC)
indicator(RSI, n = 14)

Multi-Indicator Mode

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

chart(BTC)
indicator(RSI(n = 10), RSI(n = 14), RSI(n = 21))

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

indicator(RSI(n = 14), MACD())

Multi-indicator mode requires an existing chart() — it cannot be used standalone.

Standalone Mode

When no chart() has been called, a standalone indicator chart is created. The data argument is required in this case:

indicator(RSI, data = BTC, n = 14)

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

Panel Layout

When subcharts are present, the main price panel occupies 70% of the total height by default (configurable via options(talib.chart.main = ...)), and the remaining space is divided equally among subchart panels.

See also

chart() to create the main price chart, ggplot2::set_theme() to customize chart colors.

Other Charting: chart(), chart_themes, set_theme()

Author

Serkan Korkmaz

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()