MyNixOS website logo
Description

Interface to 'TA-Lib' for Technical Analysis and Candlestick Patterns.

Interface to the 'TA-Lib' (Technical Analysis Library) 'C' library, providing access to 150+ indicators (e.g. Average Directional Movement Index (ADX), Moving Average Convergence Divergence (MACD), Relative Strength Index (RSI), Stochastic Oscillator, Bollinger Bands), candlestick pattern recognition, and rolling-window utilities. Core computations are implemented in 'C' for fast Open-High-Low-Close-Volume (OHLCV) time-series feature engineering and rule-based signal generation, with optional interactive visualization via 'plotly'.

{talib}: A Technical Analysis and Candlestick Pattern Library in R

R-CMD-check RemoteInstall Codecov testcoverage CRANstatus CRAN RStudio mirrordownloads

{talib} is an R package for technical analysis, candlestick pattern recognition, and interactive financial charting—built on the TA-Lib C library. It provides 67 technical indicators, 61 candlestick patterns, and a composable charting system powered by {plotly} and {ggplot2}. All indicator computations are implemented in C via .Call() for minimal overhead.

Alongside {TTR}, {talib} adds candlestick pattern recognition and interactive charts to the R technical analysis ecosystem.

{
    ## create a candlestick chart
    talib::chart(BTC, title = "Bitcoin (BTC)")

    ## overlay Bollinger Bands on
    ## the price panel
    talib::indicator(talib::bollinger_bands)

    ## mark Engulfing candlestick
    ## patterns on the chart
    talib::indicator(talib::engulfing, data = BTC)

    ## add RSI and volume as
    ## separate sub-panels
    talib::indicator(talib::RSI)
    talib::indicator(talib::trading_volume)
}

Indicators

Every indicator follows the same interface: pass an OHLCV data.frame or matrix and get the same type back. The return type always matches the input.

## compute Bollinger Bands
## on BTC OHLCV data
tail(
    talib::bollinger_bands(BTC)
)
#>                     UpperBand MiddleBand LowerBand
#> 2024-12-26 01:00:00 100487.38   96698.61  92909.83
#> 2024-12-27 01:00:00 100670.65   96512.96  92355.27
#> 2024-12-28 01:00:00 100632.13   96581.91  92531.69
#> 2024-12-29 01:00:00  99628.77   95576.60  91524.43
#> 2024-12-30 01:00:00  96403.53   94231.31  92059.09
#> 2024-12-31 01:00:00  95441.13   93774.23  92107.34

Candlestick Patterns

{talib} recognizes 61 candlestick patterns—from single-candle formations like Doji and Hammer to multi-candle patterns like Morning Star and Three White Soldiers. Each pattern returns a normalized score: 1 (bullish), -1 (bearish), or 0 (no pattern).

## detect Engulfing patterns:
## 1 = bullish, -1 = bearish, 0 = none
tail(
    talib::engulfing(BTC)
)
#>                     CDLENGULFING
#> 2024-12-26 01:00:00           -1
#> 2024-12-27 01:00:00            0
#> 2024-12-28 01:00:00            0
#> 2024-12-29 01:00:00           -1
#> 2024-12-30 01:00:00            0
#> 2024-12-31 01:00:00            0

Charts

Charts are built in two steps: chart() creates the price chart, then indicator() layers on technical indicators. Overlap indicators (moving averages, Bollinger Bands) draw on the price panel; oscillators (RSI, MACD) get their own sub-panels.

{
    ## price chart with two moving
    ## averages and MACD below
    talib::chart(BTC)
    talib::indicator(talib::SMA, n = 7)
    talib::indicator(talib::SMA, n = 14)
    talib::indicator(talib::MACD)
}

Multiple indicators can share a sub-panel by passing them as calls:

{
    talib::chart(BTC)
    talib::indicator(talib::BBANDS)

    ## pass multiple calls to combine
    ## them on a single sub-panel
    talib::indicator(
        talib::RSI(n = 10),
        talib::RSI(n = 14),
        talib::RSI(n = 21)
    )
}

The charting system ships with 5 built-in themes: default, hawks_and_doves, payout, tp_slapped, and trust_the_process. Switch themes with set_theme(). Both {plotly} (interactive, default) and {ggplot2} (static) backends are supported:

{
    ## switch to ggplot2 backend with
    ## the "Hawks and Doves" theme
    talib::set_theme("hawks_and_doves")
    talib::chart(BTC, title = "Bitcoin (BTC)")
    talib::indicator(talib::BBANDS)
    talib::indicator(talib::RSI)
    talib::indicator(talib::trading_volume)
}

Column selection

Indicators use the columns they need automatically. When your data has non-standard column names, remap them with formula syntax:

## remap 'price' to the close column
talib::RSI(x, cols = ~price)

## remap hi, lo, last to high, low, close
talib::stochastic(x, cols = ~ hi + lo + last)

Naming

Functions use descriptive snake_case names, but every function is aliased to its TA-Lib shorthand for compatibility with the broader ecosystem:

CategoryTA-Lib (C){talib}{talib} alias
Overlap StudiesTA_BBANDS()bollinger_bands()BBANDS()
Momentum IndicatorsTA_CCI()commodity_channel_index()CCI()
Volume IndicatorsTA_OBV()on_balance_volume()OBV()
Volatility IndicatorsTA_ATR()average_true_range()ATR()
Price TransformTA_AVGPRICE()average_price()AVGPRICE()
Cycle IndicatorsTA_HT_SINE()sine_wave()HT_SINE()
Pattern RecognitionTA_CDLHANGINGMAN()hanging_man()CDLHANGINGMAN()
## snake_case and TA-Lib aliases
## are identical
all.equal(
    target = talib::bollinger_bands(BTC),
    current = talib::BBANDS(BTC)
)
#> [1] TRUE

Installation[^1]

Install the release version from CRAN:

install.packages("talib")

Install the development version from GitHub:

pak::pak("serkor1/ta-lib-R")

Aggressive optimizations

Unknown flags passed to configure are forwarded verbatim to both the CMake build of the vendored TA-Lib and the R wrapper compile step. Rebuild from source with any compiler flags you like:

install.packages(
    "talib",
    type = "source",
    configure.args = "-O3 -march=native"
)

Or from a local clone:

git clone --recursive https://github.com/serkor1/ta-lib-R.git
cd ta-lib-R
R CMD INSTALL . --configure-args="-O3 -march=native"

Code of Conduct

Please note that {talib} is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

[^1]: TA-Lib is vendored via CMake, so a pre-installed TA-Lib is not required. Some systems (Windows in particular) may require CMake to be explicitly installed.

Metadata

Version

0.9-2

License

Unknown

Platforms (80)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arc-linux
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • sh4-linux
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows