Skip to contents

{talib} is an R-package for Technical Analysis and algorithmic Candlestick pattern recognition built on the C library TA-Lib. {talib} extends {TTR} by adding Candlestick pattern recognition to the pool of available indicators, and interactive charts via {plotly}.

TA-Lib supports 200+ indicators for Technical Analysis and Candlestick Patterns, all of which are available in {talib}.

Types of Indicators and Interface

In the core C library functions are named as TA_INDICATOR() and TA_CDLPATTERN() for indicators and patterns respectively. In the Python-wrapper the functions are named INDICATOR() and CDLPATTERN()—but this R package follows the tidyverse styleguide and therefore the naming is inconsistent with the core library and the Python wrapper. See below for an example of the mapping:

Function Group TA-Lib (core) {talib}
Overlap Studies TA_BBANDS() bollinger_bands()
Momentum Indicators TA_CCI() commodity_channel_index()
Volume Indicators TA_OBV() on_balance_volume()
Volatility Indicators TA_ATR() average_true_range()
Price Transform TA_AVGPRICE() average_price()
Cycle Indicators TA_HT_SINE() ht_sine_wave()
Pattern Recognition TA_CDLHANGINGMAN() hanging_man()

However, each function in {talib} is aliased so its consistent with the remaining ecosystem. See below:

all.equal(
    target = talib::bollinger_bands(talib::BTC),
    current = talib::BBANDS(talib::BTC)
)
#> [1] TRUE

The aliases are exported but are not a part of the documentation, but they behave exactly the same as the main functions as demonstrated above.

Basic Usage

Below are an example on how to use {talib} to calculate an indicator, identify a candlestick pattern and charting it all together.

Indicators

## identify Harami 
## patterns
tail(
    talib::harami(
        talib::BTC
    )
)
#>                     CDLHARAMI
#> 2024-12-26 01:00:00         0
#> 2024-12-27 01:00:00         0
#> 2024-12-28 01:00:00         0
#> 2024-12-29 01:00:00         0
#> 2024-12-30 01:00:00         0
#> 2024-12-31 01:00:00         0
## calculate bollinger
## bands
tail(
    talib::bollinger_bands(
        talib::BTC
    )
)
#>                         upper   middle    lower
#> 2024-12-26 01:00:00 104478.35 98217.88 91957.42
#> 2024-12-27 01:00:00 100877.73 97020.16 93162.59
#> 2024-12-28 01:00:00  99886.22 96516.01 93145.81
#> 2024-12-29 01:00:00  99871.12 96134.41 92397.71
#> 2024-12-30 01:00:00  99713.92 95620.42 91526.92
#> 2024-12-31 01:00:00  99373.89 95236.42 91098.95

Charting

Below is an example on how to use chart() and indicator().

{
    ## construct the chart
    ## with the default values
    ## (candlesticks by default)
    talib::chart(talib::BTC)

    ## chart the bollinger bands
    talib::indicator(
        talib::bollinger_bands
    )

    ## identify 'Harami'-patterns
    ## from the last 66 candles and
    ## chart 
    talib::indicator(
        talib::harami,
        data = talib::BTC,
        subset = 1:nrow(talib::BTC) %in% 300:nrow(talib::BTC)
    )
}

Installation

TA-Lib is vendored in {talib} via CMake, so it is not necessary to have TA-Lib pre-installed.1

Stable version

pak::pak("talib")

Development version

The development version can be installed by recursive cloning the repository and using the available build tools as follows:

git clone --recursive https://github.com/serkor1/ta-lib-R.git
cd ta-lib-R
make build

Use make to see package-level build-tools.

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.