Implementation:TA Lib Ta lib python OHLC Input Pattern
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Data_Preparation, Technical_Analysis |
| Last Updated | 2026-02-09 22:00 GMT |
Overview
Concrete pattern for preparing four separate OHLC numpy arrays as input to candlestick pattern recognition functions.
Description
This is a Pattern Doc documenting the data preparation pattern for CDL functions. Each CDL function requires four positional float64 numpy arrays in the order: open, high, low, close. The Cython layer validates array lengths match via check_length4 and converts to float64 via check_array.
Usage
Prepare four equal-length float64 arrays before calling any CDL pattern function.
Code Reference
Source Location
- Repository: ta-lib-python
- File: tests/conftest.py (ford_2012 fixture provides canonical OHLCV test data)
Signature
# OHLC data preparation patterns
import numpy as np
# Pattern 1: From separate arrays
open_prices = np.array([44.0, 44.3, 44.1], dtype=float)
high_prices = np.array([44.2, 44.5, 44.4], dtype=float)
low_prices = np.array([43.9, 44.0, 43.8], dtype=float)
close_prices = np.array([44.1, 44.3, 43.9], dtype=float)
# Pattern 2: From pandas DataFrame
import pandas as pd
df = pd.read_csv('prices.csv')
open_prices = df['open'] # pd.Series, auto-converted by _wrapper
high_prices = df['high']
low_prices = df['low']
close_prices = df['close']
Import
import numpy as np
import talib
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| open | np.ndarray (float64) | Yes | Opening prices |
| high | np.ndarray (float64) | Yes | High prices |
| low | np.ndarray (float64) | Yes | Low prices |
| close | np.ndarray (float64) | Yes | Closing prices |
Outputs
| Name | Type | Description |
|---|---|---|
| prepared_arrays | 4x np.ndarray (float64) | Four validated, equal-length float64 arrays |
Usage Examples
Prepare OHLC Data
import numpy as np
import talib
# Generate sample OHLC data
n = 100
close = np.cumsum(np.random.randn(n) * 0.5) + 100
open_p = close + np.random.randn(n) * 0.2
high = np.maximum(open_p, close) + np.abs(np.random.randn(n) * 0.3)
low = np.minimum(open_p, close) - np.abs(np.random.randn(n) * 0.3)
# Pass to any CDL function
doji = talib.CDLDOJI(open_p, high, low, close)
Related Pages
Implements Principle
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment