goti

package module
v1.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2026 License: MIT-0 Imports: 3 Imported by: 0

README

GoTI – Technical‑Analysis Library for Go

A lightweight, dependency‑free Go package that implements a suite of popular technical‑analysis indicators.
All indicators share a common design philosophy:

  • Thread‑safe where needed – e.g. AdaptiveDEMAMomentumOscillator.
  • Memory‑bounded – internal slices are trimmed to the minimum required capacity.
  • Consistent error handling – sentinel errors (ErrInsufficientData, ErrNoMFIData, …) are exported for errors.Is.
  • Configurable thresholds – via IndicatorConfig.
  • Ready‑for‑visualisation – each indicator can emit PlotData structures that serialize to JSON/CSV.

Package layout

  • github.com/evdnx/goti – convenience façade that re-exports everything.
  • github.com/evdnx/goti/config – shared thresholds and validation helpers.
  • github.com/evdnx/goti/indicator – all indicator implementations, moving averages, and plotting utilities.
  • github.com/evdnx/goti/suite – combined signal engine built from the individual indicators.

Table of Contents

  1. Installation
  2. Configuration
  3. Indicators
    • Relative Strength Index (RSI)
    • Stochastic Oscillator
    • Moving Average Convergence Divergence (MACD)
    • Commodity Channel Index (CCI)
    • Hull Moving Average (HMA)
    • Parabolic SAR
    • Bollinger Bands
    • Average True Range (ATR)
    • Volume Weighted Average Price (VWAP)
    • Money Flow Index (MFI)
    • Adaptive DEMA (Double Exponential Moving Average) Momentum Oscillator (ADMO)
    • Adaptive Trend Strength Oscillator (ATSO)
    • Volume‑Weighted Aroon Oscillator (VWAO)
  4. Indicator Suite
  5. Utility Functions
  6. Testing & Benchmarking
  7. Serialization Helpers
  8. License

Installation

go get github.com/evdnx/goti

The package only depends on the Go standard library. Use the top-level goti package for the façade, or import indicator, config, or suite directly when you want narrower dependencies.


Configuration

All indicators accept an IndicatorConfig that bundles the tunable thresholds and a few misc parameters.

cfg := goti.DefaultConfig()
cfg.RSIOverbought = 75          // raise overbought level for RSI
cfg.MFIOversold = 15           // tighter oversold for MFI
cfg.ATSEMAperiod = 10          // longer EMA smoothing for ATSO

Validate a config before use:

if err := cfg.Validate(); err != nil {
    // handle mis‑configuration
}

Indicators

Each indicator follows the same lifecycle:

// 1️⃣ Create
ind, err := goti.New<IndicatorName>(/*optional params*/)

// 2️⃣ Feed data (Add / AddCandle)
err = ind.Add(/*price data*/)

// 3️⃣ Query results
value, err := ind.Calculate()
bull, err := ind.IsBullishCrossover()

Core set (used by the scalping suite): Adaptive DEMA Momentum Oscillator (ADMO), Volume Weighted Aroon Oscillator (VWAO), MACD, HMA, Parabolic SAR, Bollinger Bands, ATR, VWAP, and MFI. The suite uses adaptive indicators that adjust to volatility regimes for better scalping performance.

Relative Strength Index (RSI)

  • Package: relative_strength_index.go
  • Default period: 5
  • Key methods: Add, Calculate, IsBullishCrossover, IsBearishCrossover, IsDivergence, GetPlotData

Stochastic Oscillator

  • Package: stochastic_oscillator.go
  • Default periods: %K=14, %D=3 (suite uses a shorter 9/3 for scalping)
  • Key methods: Add, Calculate, IsOverbought, IsOversold, GetPlotData

Moving Average Convergence Divergence (MACD)

  • Package: macd.go
  • Default periods: 12/26/9 (suite uses 5/13/4 for faster turns)
  • Key methods: Add, Calculate, GetMACDValues, GetSignalValues, GetHistogramValues, GetPlotData

Commodity Channel Index (CCI)

  • Package: commodity_channel_index.go
  • Default period: 20 (suite uses 10)
  • Key methods: Add, Calculate, IsOverbought, IsOversold, GetPlotData

Money Flow Index (MFI)

  • Package: money_flow_index.go
  • Default period: 5, volume‑scaled by MFIVolumeScale (default 300 000)
  • Sentinel error: ErrNoMFIData (use errors.Is)

Volume‑Weighted Aroon Oscillator (VWAO)

  • Package: volume_weighted_aroon_oscillator.go
  • Default period: 14
  • Strong‑trend threshold: VWAOStrongTrend (default 70)

Hull Moving Average (HMA)

  • Package: hull_moving_average.go
  • Default period: 9
  • Crossover helpers (IsBullishCrossover, IsBearishCrossover) and trend detection (GetTrendDirection).

Parabolic SAR

  • Package: parabolic_sar.go
  • Default step/max: 0.02 / 0.2
  • Key methods: Add, Calculate, IsUptrend, GetPlotData

Bollinger Bands

  • Package: bollinger_bands.go
  • Default period/multiplier: 20 / 2
  • Key methods: Add, Calculate, GetPlotData

Average True Range (ATR)

  • Package: average_true_range.go
  • Default period: 14
  • Functional option: WithCloseValidation(bool) to disable the “close must lie between high/low” check.

Volume Weighted Average Price (VWAP)

  • Package: vwap.go
  • Key methods: Add, Calculate, GetPlotData

Adaptive DEMA (Double Exponential Moving Average) Momentum Oscillator (ADMO)

  • Package: adaptive_dema_momentum_oscillator.go
  • Features:
    • Dual EMA → DEMA → adaptive momentum calculation.
    • Zero‑line crossovers, significant‑price‑jump heuristics, and divergence detection.
    • Fully thread‑safe (sync.RWMutex).

Adaptive Trend Strength Oscillator (ATSO)

  • Package: adaptive_trend_strength_oscillator.go
  • Adaptive period based on recent volatility, EMA‑smoothed output.
  • Crossover detection scans the entire raw series for sign changes (improved over the original “last‑two‑points only” logic).

Indicator Suite

ScalpingIndicatorSuite aggregates the scalping-focused stack (Adaptive DEMA Momentum Oscillator, Volume Weighted Aroon Oscillator, MACD, HMA, Parabolic SAR, Bollinger Bands, ATR, VWAP, MFI) and provides a weighted engine tuned for fast reversals and intraday follow-through. The suite uses adaptive indicators that automatically adjust to volatility changes, making it more responsive to market conditions than fixed-period indicators. The legacy NewIndicatorSuite* helpers are preserved as aliases.

suite, err := goti.NewScalpingIndicatorSuite()
suite.Add(high, low, close, volume) // feeds every sub-indicator
signal, err := suite.GetCombinedSignal() // “Strong Bullish”, “Weak Bearish”, etc.

The suite also offers:

  • GetCombinedBearishSignal()
  • GetDivergenceSignals() – ADMO, VWAO, and MFI divergence detection.
  • Reset() – clears every sub‑indicator while preserving the config.
  • GetPlotData() – collates plot series for every indicator (including ATR/VWAP).

Utility Functions

FunctionDescriptionkeepLast[T any](s []T, n int) []TReturn the last n elements of a slice (generic).
GenerateTimestamps(start, count, interval int64) []int64Produce Unix‑epoch timestamps for chart axes.
FormatPlotDataJSON(data []PlotData) (string, error)Marshal a slice of PlotData to JSON (validated lengths).
FormatPlotDataCSV(data []PlotData) (string, error)Serialize PlotData to CSV.
clamp(v, min, max float64) float64Clamp a value to a closed interval.
calculateEMA, calculateWMA, calculateStandardDeviationCore numeric kernels used by the indicators.

All helpers are deliberately publicly exported only when needed; the rest remain package‑private.


Testing & Benchmarking

The repository ships with a comprehensive test matrix (*_test.go) covering:

  • Correctness of each indicator (edge cases, period changes, resets).
  • Defensive‑copy safety of getters.
  • Divergence and crossover detection logic.

Run the full suite:

go test ./...

Benchmarks are located in *_bench_test.go. Example:

go test -bench=. -benchmem ./...

Typical benchmark categories:

  • Add – cost of ingesting a single price/candle.
  • Full pipelineAdd + Calculate.
  • Signal detectionIsBullishCrossover, IsDivergence, etc.
  • Plot data generation – JSON/CSV serialization overhead.

Feel free to add new benchmarks for custom workloads; the helper functions (genOHLC, randVals, etc.) are deterministic to keep results reproducible.


Serialization Helpers

PlotData is the canonical container for charting libraries:

type PlotData struct {
    Name      string    `json:"name"`
    X         []float64 `json:"x"`
    Y         []float64 `json:"y"`
    Type      string    `json:"type,omitempty"`   // "line" or "scatter"
    Signal    string    `json:"signal,omitempty"` // optional label for scatter series
    Timestamp []int64   `json:"timestamp,omitempty"`
}

Both JSON and CSV exporters validate that len(X) == len(Y) and return a clear error if the invariant is broken.


License

This library is released under the MIT License. Feel free to fork, modify, and use it in commercial projects.


Quick‑start Example

package main

import (
    "fmt"
    "github.com/evdnx/goti"
)

func main() {
    // Initialise a suite with custom thresholds.
    cfg := goti.DefaultConfig()
    cfg.RSIOverbought = 80
    cfg.RSIOversold = 20
    suite, _ := goti.NewScalpingIndicatorSuiteWithConfig(cfg)

    // Simulate a stream of OHLCV data.
    data := []struct{ h, l, c, v float64 }{
        {101, 99, 100, 1_000},
        {102, 98, 101, 1_200},
        // …
    }

    for _, d := range data {
        if err := suite.Add(d.h, d.l, d.c, d.v); err != nil {
            panic(err)
        }
    }

    // Get a combined signal.
    signal, _ := suite.GetCombinedSignal()
    fmt.Println("Combined signal:", signal)

    // Export chart data for the UI.
    plot := suite.GetPlotData(1625097600000, 60_000) // start‑time, 1‑min interval
    json, _ := goti.FormatPlotDataJSON(plot)
    fmt.Println(json)
}

Documentation

Index

Constants

View Source
const (
	DefaultAMDOOverbought = config.DefaultAMDOOverbought
	DefaultAMDOOversold   = config.DefaultAMDOOversold
)
View Source
const (
	DefaultLength      = indicator.DefaultLength
	DefaultStdevLength = indicator.DefaultStdevLength
	DefaultStdWeight   = indicator.DefaultStdWeight
)

Variables

View Source
var (
	ErrNoMFIData            = indicator.ErrNoMFIData
	ErrInsufficientDataCalc = indicator.ErrInsufficientDataCalc
)
View Source
var (
	ErrInsufficientData = indicator.ErrInsufficientData
	ErrInvalidParams    = indicator.ErrInvalidParams
)

Functions

func EMASmoothingFactor

func EMASmoothingFactor(n int) float64

func FormatPlotDataCSV

func FormatPlotDataCSV(data []indicator.PlotData) (string, error)

func FormatPlotDataJSON

func FormatPlotDataJSON(data []indicator.PlotData) (string, error)

func GenerateTimestamps

func GenerateTimestamps(startTime int64, count int, interval int64) []int64

func NewAdaptiveDEMAMomentumOscillator

func NewAdaptiveDEMAMomentumOscillator() (*indicator.AdaptiveDEMAMomentumOscillator, error)

func NewAdaptiveDEMAMomentumOscillatorWithParams

func NewAdaptiveDEMAMomentumOscillatorWithParams(length, stdevLength int, stdWeight float64, cfg config.IndicatorConfig) (*indicator.AdaptiveDEMAMomentumOscillator, error)

func NewAdaptiveTrendStrengthOscillator

func NewAdaptiveTrendStrengthOscillator() (*indicator.AdaptiveTrendStrengthOscillator, error)

func NewAdaptiveTrendStrengthOscillatorWithParams

func NewAdaptiveTrendStrengthOscillatorWithParams(shortPeriod, longPeriod, volatilityPeriod int, cfg config.IndicatorConfig) (*indicator.AdaptiveTrendStrengthOscillator, error)

func NewAverageTrueRange

func NewAverageTrueRange() (*indicator.AverageTrueRange, error)

func NewAverageTrueRangeWithParams

func NewAverageTrueRangeWithParams(period int, opts ...indicator.ATROption) (*indicator.AverageTrueRange, error)

func NewBollingerBands added in v1.0.2

func NewBollingerBands() (*indicator.BollingerBands, error)

func NewBollingerBandsWithParams added in v1.0.2

func NewBollingerBandsWithParams(period int, multiplier float64) (*indicator.BollingerBands, error)

func NewCommodityChannelIndex added in v1.0.2

func NewCommodityChannelIndex() (*indicator.CommodityChannelIndex, error)

func NewCommodityChannelIndexWithParams added in v1.0.2

func NewCommodityChannelIndexWithParams(period int) (*indicator.CommodityChannelIndex, error)

func NewHullMovingAverage

func NewHullMovingAverage() (*indicator.HullMovingAverage, error)

func NewHullMovingAverageWithParams

func NewHullMovingAverageWithParams(period int) (*indicator.HullMovingAverage, error)

func NewIndicatorSuite

func NewIndicatorSuite() (*suite.ScalpingIndicatorSuite, error)

Backwards-compatible aliases for callers expecting the old names.

func NewIndicatorSuiteWithConfig

func NewIndicatorSuiteWithConfig(cfg config.IndicatorConfig) (*suite.ScalpingIndicatorSuite, error)

func NewMACD added in v1.0.2

func NewMACD() (*indicator.MACD, error)

func NewMACDWithParams added in v1.0.2

func NewMACDWithParams(fastPeriod, slowPeriod, signalPeriod int) (*indicator.MACD, error)

func NewMoneyFlowIndex

func NewMoneyFlowIndex() (*indicator.MoneyFlowIndex, error)

func NewMoneyFlowIndexWithParams

func NewMoneyFlowIndexWithParams(period int, cfg config.IndicatorConfig) (*indicator.MoneyFlowIndex, error)

func NewMovingAverage

func NewMovingAverage(maType indicator.MovingAverageType, period int) (*indicator.MovingAverage, error)

func NewOptimizedScalpingIndicatorSuite added in v1.0.6

func NewOptimizedScalpingIndicatorSuite() (*suite.OptimizedScalpingIndicatorSuite, error)

func NewOptimizedScalpingIndicatorSuiteWithConfig added in v1.0.6

func NewOptimizedScalpingIndicatorSuiteWithConfig(cfg config.IndicatorConfig) (*suite.OptimizedScalpingIndicatorSuite, error)

func NewParabolicSAR added in v1.0.2

func NewParabolicSAR() (*indicator.ParabolicSAR, error)

func NewParabolicSARWithParams added in v1.0.2

func NewParabolicSARWithParams(step, maxStep float64) (*indicator.ParabolicSAR, error)

func NewRelativeStrengthIndex

func NewRelativeStrengthIndex() (*indicator.RelativeStrengthIndex, error)

func NewRelativeStrengthIndexWithParams

func NewRelativeStrengthIndexWithParams(period int, cfg config.IndicatorConfig) (*indicator.RelativeStrengthIndex, error)

func NewScalpingIndicatorSuite added in v1.0.2

func NewScalpingIndicatorSuite() (*suite.ScalpingIndicatorSuite, error)

func NewScalpingIndicatorSuiteWithConfig added in v1.0.2

func NewScalpingIndicatorSuiteWithConfig(cfg config.IndicatorConfig) (*suite.ScalpingIndicatorSuite, error)

func NewStochasticOscillator added in v1.0.2

func NewStochasticOscillator() (*indicator.StochasticOscillator, error)

func NewStochasticOscillatorWithParams added in v1.0.2

func NewStochasticOscillatorWithParams(kPeriod, dPeriod int) (*indicator.StochasticOscillator, error)

func NewVWAP added in v1.0.2

func NewVWAP() *indicator.VWAP

func NewVolumeWeightedAroonOscillator

func NewVolumeWeightedAroonOscillator() (*indicator.VolumeWeightedAroonOscillator, error)

func NewVolumeWeightedAroonOscillatorWithParams

func NewVolumeWeightedAroonOscillatorWithParams(period int, cfg config.IndicatorConfig) (*indicator.VolumeWeightedAroonOscillator, error)

func WithCloseValidation

func WithCloseValidation(enabled bool) indicator.ATROption

Types

type ATROption

type ATROption = indicator.ATROption

type AdaptiveDEMAMomentumOscillator

type AdaptiveDEMAMomentumOscillator = indicator.AdaptiveDEMAMomentumOscillator

---- Adaptive DEMA Momentum Oscillator ----

type AdaptiveTrendStrengthOscillator

type AdaptiveTrendStrengthOscillator = indicator.AdaptiveTrendStrengthOscillator

---- Adaptive Trend Strength Oscillator ----

type AverageTrueRange

type AverageTrueRange = indicator.AverageTrueRange

---- Average True Range ----

type BollingerBands added in v1.0.2

type BollingerBands = indicator.BollingerBands

type CommodityChannelIndex added in v1.0.2

type CommodityChannelIndex = indicator.CommodityChannelIndex

---- Commodity Channel Index ----

type HullMovingAverage

type HullMovingAverage = indicator.HullMovingAverage

---- Hull Moving Average ----

type IndicatorConfig

type IndicatorConfig = config.IndicatorConfig

Re-export configuration so callers can keep using the top-level package.

func DefaultConfig

func DefaultConfig() IndicatorConfig

type IndicatorSuite

type IndicatorSuite = suite.ScalpingIndicatorSuite

type MACD added in v1.0.2

type MACD = indicator.MACD

---- MACD ----

type MoneyFlowIndex

type MoneyFlowIndex = indicator.MoneyFlowIndex

---- Money Flow Index ----

type MovingAverage

type MovingAverage = indicator.MovingAverage

type MovingAverageType

type MovingAverageType = indicator.MovingAverageType

---- Moving averages ----

type OptimizedScalpingIndicatorSuite added in v1.0.6

type OptimizedScalpingIndicatorSuite = suite.OptimizedScalpingIndicatorSuite

type ParabolicSAR added in v1.0.2

type ParabolicSAR = indicator.ParabolicSAR

---- Parabolic SAR ----

type PlotData

type PlotData = indicator.PlotData

---- Shared data helpers ----

type RelativeStrengthIndex

type RelativeStrengthIndex = indicator.RelativeStrengthIndex

---- RSI ----

type ScalpingIndicatorSuite added in v1.0.2

type ScalpingIndicatorSuite = suite.ScalpingIndicatorSuite

---- Indicator suite ----

type StochasticOscillator added in v1.0.2

type StochasticOscillator = indicator.StochasticOscillator

---- Stochastic Oscillator ----

type VWAP added in v1.0.2

type VWAP = indicator.VWAP

---- VWAP ----

type VolumeWeightedAroonOscillator

type VolumeWeightedAroonOscillator = indicator.VolumeWeightedAroonOscillator

---- Volume Weighted Aroon Oscillator ----

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL