Skip to content
DuckDB community extension

talib

Technical Analysis Library (TA-Lib) functions for DuckDB -- 100+ indicators for financial market analysis.

01 / SETUP

Install and load

Run these commands in a Haybarn SQL session. The extension is available from the community repository.

Haybarn 2.0.0 · SQL
INSTALL talib FROM community;
LOAD talib FROM community;

Using upstream DuckDB? Follow the maintainer’s installation instructions.

02 / QUERY

Usage example

It uses NVDA's real daily OHLCV for 2026-01-01 → 2026-01-31 (20 trading days):

SQL
--  It uses NVDA's real daily OHLCV for 2026-01-01 → 2026-01-31 (20 trading days):
CREATE TABLE ohlc AS
  SELECT * FROM (VALUES
    ('NVDA', DATE '2026-01-02', 189.84, 192.93, 188.26, 188.85, 148240500),
    ('NVDA', DATE '2026-01-05', 191.76, 193.63, 186.15, 188.12, 183529733),
    ('NVDA', DATE '2026-01-06', 190.52, 192.17, 186.82, 187.24, 176862604),
    ('NVDA', DATE '2026-01-07', 188.57, 191.37, 186.56, 189.11, 153543200),
    ('NVDA', DATE '2026-01-08', 189.11, 189.55, 183.71, 185.04, 172457048),
    ('NVDA', DATE '2026-01-09', 185.08, 186.34, 183.67, 184.86, 131327534),
    ('NVDA', DATE '2026-01-12', 183.22, 187.12, 183.02, 184.94, 137968500),
    ('NVDA', DATE '2026-01-13', 185.00, 188.11, 183.40, 185.81, 160128939),
    ('NVDA', DATE '2026-01-14', 184.32, 184.46, 180.80, 183.14, 159586135),
    ('NVDA', DATE '2026-01-15', 186.50, 189.70, 186.33, 187.05, 206188642),
    ('NVDA', DATE '2026-01-16', 189.08, 190.44, 186.08, 186.23, 187967200),
    ('NVDA', DATE '2026-01-20', 181.90, 182.38, 177.61, 178.07, 223345300),
    ('NVDA', DATE '2026-01-21', 179.05, 185.38, 178.40, 183.32, 200381000),
    ('NVDA', DATE '2026-01-22', 184.75, 186.17, 183.93, 184.84, 139636626),
    ('NVDA', DATE '2026-01-23', 187.50, 189.60, 186.82, 187.67, 142748100),
    ('NVDA', DATE '2026-01-26', 187.16, 189.12, 185.99, 186.47, 124799649),
    ('NVDA', DATE '2026-01-27', 187.24, 190.00, 185.70, 188.52, 143711600),
    ('NVDA', DATE '2026-01-28', 191.27, 192.35, 189.84, 191.52, 148552700),
    ('NVDA', DATE '2026-01-29', 191.34, 193.48, 186.06, 192.51, 171764400),
    ('NVDA', DATE '2026-01-30', 191.21, 194.49, 189.47, 191.13, 179489500)
  ) AS t(ticker, date, open, high, low, close, volume);

-- Three ways to compute SMA(14) on ohlc:
-- 1️⃣ List form (shortest & fastest): whole-series, returns a LIST<DOUBLE>
SELECT t_sma(list(close ORDER BY date), 14)
FROM ohlc WHERE ticker = 'NVDA';

-- 2️⃣ Window, bounded frame (fast, one row per input): recommended for dashboards
SELECT date, close,
  ta_sma(close, 14) OVER (ORDER BY date ROWS BETWEEN 13 PRECEDING AND CURRENT ROW) AS sma_14
FROM ohlc WHERE ticker = 'NVDA'
ORDER BY date;

-- 3️⃣ Window, default frame (shortest SQL, but O(N²) — avoid on large tables)
SELECT date, close, ta_sma(close, 14) OVER (ORDER BY date) AS sma_14
FROM ohlc WHERE ticker = 'NVDA'
ORDER BY date;

-- More examples:
-- 📐 MACD with STRUCT output (needs ~35 bars to warm up — with only 20 days
-- of history here every row is still NULL; add more history to see real values)
SELECT t_macd(list(close ORDER BY date), 12, 26, 9) FROM ohlc WHERE ticker = 'NVDA';

-- 🕯️ Candlestick pattern detection — returns 0/1 per bar (no doji in this window)
SELECT t_cdldoji(list(open ORDER BY date), list(high ORDER BY date),
                 list(low ORDER BY date), list(close ORDER BY date))
FROM ohlc WHERE ticker = 'NVDA';

Provided by neuesql. Not yet verified on Haybarn 2.0.0.

Sample data & setup

About this extension

100+ TA-Lib indicators as native DuckDB functions: overlap studies

Project overview from the community descriptor.

Documentation and resources

Project and build details
Repository
neuesql/atm_talib
License
MIT
Maintainers
neuesql, wuqunfei
Written in
C++
Build source
631348e25c17
Build definition
Community descriptor