2026-07-22 15:40:16 +09:00
# talib
Go wrapper for selected [TA-Lib ](https://ta-lib.org/ ) functions using [`purego` ](https://github.com/ebitengine/purego ) to dynamically load the native TA-Lib shared library at runtime.
2026-07-24 18:27:36 +09:00
This project currently exposes a focused subset of TA-Lib functions:
2026-07-22 15:40:16 +09:00
2026-07-23 11:05:32 +09:00
**Cycle Indicators (Hilbert Transform)**
2026-07-22 15:40:16 +09:00
- `HT_DCPERIOD`
- `HT_DCPHASE`
- `HT_PHASOR`
- `HT_SINE`
- `HT_TRENDMODE`
2026-07-23 11:05:32 +09:00
**Math Operators**
- `Add` , `Sub` , `Mult` , `Div`
- `Max` , `MaxIndex` , `Min` , `MinIndex`
- `MinMax` , `MinMaxIndex`
2026-07-22 17:18:22 +09:00
- `Sum`
2026-07-22 15:40:16 +09:00
2026-07-23 11:05:32 +09:00
**Math Transforms**
- Trigonometric: `Cos` , `Sin` , `Tan` , `ACos` , `ASin` , `ATan`
- Hyperbolic: `CosH` , `SinH` , `TanH`
- Exponential/Logarithmic: `Exp` , `Ln` , `Log10`
- Rounding: `Ceil` , `Floor` , `Sqrt`
2026-07-24 13:37:34 +09:00
**Momentum Indicators**
2026-07-24 18:27:36 +09:00
- Directional Movement: `ADX` , `ADXR` , `DX` , `MinusDI` , `MinusDM` , `PlusDI` , `PlusDM`
2026-07-28 16:23:50 +09:00
- Oscillators: `APO` , `Aroon` , `AroonOsc` , `BOP` , `CCI` , `CMO` , `CMOU` , `IMI` , `MFI` , `MOM` , `PPO` , `RSI` , `Trix` , `WillR` , `UltOsc`
2026-07-24 13:37:34 +09:00
- Rate of Change: `ROC` , `ROCP` , `ROCR` , `ROCR100`
2026-07-24 18:27:36 +09:00
- MACD family: `MACD` , `MACDExt` , `MACDFix`
- Stochastic family: `Stoch` , `StochF` , `StochRSI`
**Overlap Studies**
2026-07-27 16:04:46 +09:00
- `AccBands` , `BBands` , `DEMA` , `EMA` , `HT_TRENDLINE` , `KAMA` , `MA` , `MAMA` , `MAVP` , `MidPoint` , `MidPrice` , `SAR` , `SARExt` , `SMA` , `T3` , `TEMA` , `TRIMA` , `WMA`
2026-07-24 13:37:34 +09:00
2026-07-27 16:52:33 +09:00
**Price Transforms**
- `AvgPrice` , `MedPrice` , `TypPrice` , `WCLPrice`
**Statistic Functions**
2026-07-27 18:10:46 +09:00
- `AvgDev` , `Beta` , `Correl` , `LinearReg` , `LinearRegAngle` , `LinearRegIntercept` , `LinearRegSlope` , `StdDev` , `TSF` , `Var`
2026-07-27 16:52:33 +09:00
2026-07-28 14:20:52 +09:00
**Volatility Indicators**
- `ATR` , `NATR` , `TRANGE`
**Volume Indicators**
- `AD` , `ADOsc` , `CMF` , `NVI` , `OBV` , `PVI` , `PVO`
2026-07-28 16:23:50 +09:00
**Pattern Recognition**
- `Cdl2Crows` , `Cdl3BlackCrows` , `Cdl3Inside` , `Cdl3LineStrike` , `Cdl3Outside` , `Cdl3StarsInSouth` , `Cdl3WhiteSoldiers`
- `CdlAbandonedBaby` , `CdlAdvanceBlock` , `CdlBeltHold` , `CdlBreakaway` , `CdlClosingMarubozu` , `CdlConcealBabysWall` , `CdlCounterAttack`
- `CdlDarkCloudCover` , `CdlDoji` , `CdlDojiStar` , `CdlDragonflyDoji` , `CdlEngulfing` , `CdlEveningDojiStar` , `CdlEveningStar`
- `CdlGapSideBySideWhite` , `CdlGravestoneDoji` , `CdlHammer` , `CdlHangingMan` , `CdlHarami` , `CdlHaramiCross` , `CdlHighWave`
- `CdlHikkake` , `CdlHikkakeMod` , `CdlHomingPigeon` , `CdlIdentical3Crows` , `CdlInNeck` , `CdlInvertedHammer` , `CdlKicking` , `CdlKickingByLength`
2026-07-22 15:40:16 +09:00
## Requirements
- Go `1.26`
- A native TA-Lib shared library installed on the host system
This package does **not** bundle TA-Lib itself. You must install the native library separately.
## How library loading works
2026-07-28 12:25:24 +09:00
Call `talib.Load()` once before using any indicator function. After loading, you can call `talib.Version()` to read the native TA-Lib version string. The loader looks for the platform-specific library name:
2026-07-22 15:40:16 +09:00
- macOS: `libta-lib.dylib`
- Linux: `libta-lib.so`
- Windows: `libta-lib.dll`
Lookup order:
1. `$TA_LIB_PATH/<library file>`
2. `./<library file>`
3. `/usr/local/lib/<library file>`
4. `/usr/lib/<library file>`
## Installing TA-Lib
### macOS
If you use Homebrew:
```bash
brew install ta-lib
```
If the library is installed outside the default lookup paths, set:
```bash
export TA_LIB_PATH = /path/to/lib
```
### Linux
Install TA-Lib with your package manager if available, or build it from source and place the shared library in a standard library directory such as `/usr/local/lib` .
### Windows
Install the TA-Lib DLL and make sure `libta-lib.dll` is reachable through `TA_LIB_PATH` or from the current working directory.
## Usage
```go
package main
import (
"fmt"
"log"
"math"
"beejay.kim/lib/talib"
)
func main () {
if _ , err := talib . Load (); err != nil {
log . Fatal ( err )
}
2026-07-28 12:25:24 +09:00
fmt . Println ( "TA-Lib version:" , talib . Version ())
2026-07-22 15:40:16 +09:00
var series [] float64
for i := 0 ; i < 100 ; i ++ {
series = append ( series , math . Sin ( float64 ( i ) / 7 ) * 4.5 + math . Cos ( float64 ( i ) / 19 ) * 1.75 )
}
period := talib . HT_DCPERIOD ( series )
fmt . Println ( period )
2026-07-22 17:18:22 +09:00
sum := talib . Add ( series , series )
2026-07-22 15:40:16 +09:00
fmt . Println ( sum )
2026-07-22 17:18:22 +09:00
rollingMax := talib . Max ( series , 14 )
fmt . Println ( rollingMax )
2026-07-22 15:40:16 +09:00
}
```
## API notes
- Indicator functions return `nil` when the underlying TA-Lib call fails.
2026-07-28 12:25:24 +09:00
- `Version()` returns the TA-Lib version string exposed by `TA_GetVersionString` (call after `Load()` ).
2026-07-22 17:18:22 +09:00
- Native TA-Lib functions are exposed with Go-style exported names such as `Add` , `Div` , `Max` , and `Sum` .
2026-07-24 18:27:36 +09:00
- Functions accepting a moving-average type use the `MAType` constant (`MA_SMA` , `MA_EMA` , `MA_WMA` , `MA_DEMA` , `MA_TEMA` , `MA_TRIMA` , `MA_KAMA` , `MA_MAMA` , `MA_T3` ).
- Functions returning multiple outputs (e.g. `Aroon` , `MACD` , `Stoch` ) return multiple slices; all are `nil` on failure.
2026-07-28 16:23:50 +09:00
- Pattern-recognition functions (`Cdl*` ) return `[]int32` signals; typical values are `-100` (bearish), `0` (no pattern), and `100` (bullish).
2026-07-22 15:40:16 +09:00
## Project status
This is currently a focused wrapper around a limited subset of TA-Lib. Additional indicators can be added by registering more native functions in `Load()` and exposing Go wrappers for them.