Add a full Momentum Indicators category (momentum_indicators.go) with 26 new wrapped functions: ADX, ADXR, APO, AROON, AROONOSC, BOP, CCI, CMO, DX, IMI, MACD, MACDEXT, MACDFIX, MFI, MOM, MINUS_DI, MINUS_DM, PLUS_DI, PLUS_DM, PPO, ROC, ROCP, ROCR, ROCR100, RSI, STOCH, STOCHF, STOCHRSI, TRIX, ULTOSC, WILLR - Register all new native symbols in Load() (loader.go) - Declare corresponding native function variables in functions.go - Add MAType enum (ta_ma_type.go) for MA-type parameters (SMA, EMA, WMA, DEMA, TEMA, TRIMA, KAMA, MAMA, T3) - Add taResult constants (ta_result.go) mirroring TA-Lib return codes - Each wrapper includes a doc comment with formula, interpretation, and known behavioral edge-case notes
123 lines
3.2 KiB
Markdown
123 lines
3.2 KiB
Markdown
# 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.
|
|
|
|
This project currently exposes a small subset of TA-Lib functions:
|
|
|
|
**Cycle Indicators (Hilbert Transform)**
|
|
- `HT_DCPERIOD`
|
|
- `HT_DCPHASE`
|
|
- `HT_PHASOR`
|
|
- `HT_SINE`
|
|
- `HT_TRENDMODE`
|
|
|
|
**Math Operators**
|
|
- `Add`, `Sub`, `Mult`, `Div`
|
|
- `Max`, `MaxIndex`, `Min`, `MinIndex`
|
|
- `MinMax`, `MinMaxIndex`
|
|
- `Sum`
|
|
|
|
**Math Transforms**
|
|
- Trigonometric: `Cos`, `Sin`, `Tan`, `ACos`, `ASin`, `ATan`
|
|
- Hyperbolic: `CosH`, `SinH`, `TanH`
|
|
- Exponential/Logarithmic: `Exp`, `Ln`, `Log10`
|
|
- Rounding: `Ceil`, `Floor`, `Sqrt`
|
|
|
|
**Momentum Indicators**
|
|
- Directional Movement: `ADX`, `ADXR`, `DX`, `MINUS_DI`, `MINUS_DM`, `PLUS_DI`, `PLUS_DM`
|
|
- Oscillators: `APO`, `AROON`, `AROONOSC`, `BOP`, `CCI`, `CMO`, `IMI`, `MFI`, `MOM`, `PPO`, `RSI`, `TRIX`, `WILLR`, `ULTOSC`
|
|
- Rate of Change: `ROC`, `ROCP`, `ROCR`, `ROCR100`
|
|
- MACD family: `MACD`, `MACDEXT`, `MACDFIX`
|
|
- Stochastic family: `STOCH`, `STOCHF`, `STOCHRSI`
|
|
|
|
## 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
|
|
|
|
Call `talib.Load()` once before using any indicator function. The loader looks for the platform-specific library name:
|
|
|
|
- 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)
|
|
}
|
|
|
|
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)
|
|
|
|
sum := talib.Add(series, series)
|
|
fmt.Println(sum)
|
|
|
|
rollingMax := talib.Max(series, 14)
|
|
fmt.Println(rollingMax)
|
|
}
|
|
```
|
|
|
|
## API notes
|
|
|
|
- Indicator functions return `nil` when the underlying TA-Lib call fails.
|
|
- Native TA-Lib functions are exposed with Go-style exported names such as `Add`, `Div`, `Max`, and `Sum`.
|
|
- Functions accepting a moving-average type use the `MAType` constant (`SMA`, `EMA`, `WMA`, `DEMA`, `TEMA`, `TRIMA`, `KAMA`, `MAMA`, `T3`).
|
|
- Functions returning two outputs (e.g. `AROON`, `MACD`, `STOCH`) return multiple slices; all are `nil` on failure.
|
|
|
|
## 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.
|