abstract

package
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package abstract describes every TA-Lib function at run time and calls one chosen by name: the Go form of TA-Lib's Abstract API.

Lookup finds a function by name, and All and InGroup enumerate them. A FuncInfo reports the function's group, flags, inputs, optional parameters with their domains and defaults, outputs and attributes. FuncInfo.NewCall returns a ParamHolder: bind the inputs, the parameters and the outputs, then call it.

f, _ := abstract.Lookup("SMA")
call := f.NewCall(talib.NewCore())
_ = call.SetInput(0, closes)
_ = call.SetOptInputInteger(0, 30)
_ = call.SetOutput(0, out)
r, err := call.Call(0, len(closes)-1)

A call goes through the function's method on talib.Core, so it returns the same values and the same errors as a direct call. Every error is a talib.RetCode.

The descriptions are immutable and safe to share between goroutines; a ParamHolder belongs to one goroutine.

Documentation: https://ta-lib.org/api/abstract/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FunctionDescriptionXML

func FunctionDescriptionXML() string

FunctionDescriptionXML returns the machine-readable description of every function: the XML document C's TA_FunctionDescriptionXML returns, byte for byte.

func RuntimeInfo

func RuntimeInfo(key string) (int, error)

RuntimeInfo returns one run-time state of this library, by key: the Go analog of C's TA_GetRuntimeInfo. The keys: https://ta-lib.org/spec/abstract/#runtime-info.

An unknown key is talib.BadParam.

Types

type Domain

type Domain interface {
	// contains filtered or unexported methods
}

Domain is the values an optional parameter accepts: a RealRange, RealList, IntegerRange or IntegerList, and nothing else.

type FuncFlags

type FuncFlags uint32

FuncFlags are the bit flags of a function. The values are C's TA_FUNC_FLG_*.

const (
	// FuncOverlap: the output is on the input's scale and overlays a price chart.
	FuncOverlap FuncFlags = 0x01000000
	// FuncStream: a streaming (one bar at a time) API exists for the function.
	FuncStream FuncFlags = 0x02000000
	// FuncVolumeUsed: the output is over the volume data.
	FuncVolumeUsed FuncFlags = 0x04000000
	// FuncUnstablePeriod: the function owns an unstable-period id: see
	// [FuncInfo.UnstableID].
	FuncUnstablePeriod FuncFlags = 0x08000000
	// FuncCandlestick: a candlestick pattern function: every integer output is a
	// pattern output.
	FuncCandlestick FuncFlags = 0x10000000
	// FuncPathDependent: the output depends on where the caller started, so it may
	// never converge across ranges.
	FuncPathDependent FuncFlags = 0x20000000
	// FuncNanInfOutput: some inputs have no finite result, so a successful call
	// can return NaN or +/-Inf.
	FuncNanInfOutput FuncFlags = 0x40000000
	// FuncPeriod1Identity: a period of 1 performs no smoothing: the output is a
	// bit-exact copy of the input.
	FuncPeriod1Identity FuncFlags = 0x00000001
	// FuncDisplayShift: at least one output carries [OutDisplayShift]; without it
	// every output's display shift is 0.
	FuncDisplayShift FuncFlags = 0x00000002
	// FuncUsesTranscendental: the function calls a transcendental math function,
	// so a value may differ slightly between languages, between a stream and a
	// batch call, and between machines. Not set on a function that reaches one
	// only when an MA-type parameter selects MAMA, ALMA or SSF.
	FuncUsesTranscendental FuncFlags = 0x00000004
)

The FuncFlags bits.

type FuncInfo

type FuncInfo struct {
	// contains filtered or unexported fields
}

FuncInfo is everything the library knows about one function's batch form. Obtain one from Lookup, All or InGroup. Its accessors return copies, so nothing a caller does with them changes the description.

func All

func All() []FuncInfo

All returns every function, in name order.

func InGroup

func InGroup(g Group) []FuncInfo

InGroup returns the functions of group g, in name order.

func Lookup

func Lookup(name string) (FuncInfo, bool)

Lookup returns the function named name in any ASCII casing, such as "SMA" or "sma", and false when there is none.

func (FuncInfo) Attributes

func (f FuncInfo) Attributes() string

Attributes returns what no flag can carry, such as an output's reference levels, as one JSON object, or "{}" when there is none: the same bytes as C's TA_GetFuncAttributes. Ignore a key you do not know, since a release may add one: https://ta-lib.org/spec/abstract/#attributes.

func (FuncInfo) Flags

func (f FuncInfo) Flags() FuncFlags

Flags returns the function's flags.

func (FuncInfo) Group

func (f FuncInfo) Group() Group

Group returns the function's category.

func (FuncInfo) HasFlags

func (f FuncInfo) HasFlags(mask FuncFlags) bool

HasFlags reports whether every bit of mask is set.

func (FuncInfo) Hint

func (f FuncInfo) Hint() string

Hint returns a one-line description, or "" when there is none.

func (FuncInfo) Inputs

func (f FuncInfo) Inputs() []InputInfo

Inputs returns the inputs, in call order. The components of a price input are one input, so ADX has one input, not three: see InputInfo.Requires.

func (FuncInfo) Name

func (f FuncInfo) Name() string

Name returns the canonical name, such as "SMA": also the name of the talib.Core method that computes the function.

func (FuncInfo) NewCall

func (f FuncInfo) NewCall(core *talib.Core) *ParamHolder

NewCall returns a holder to bind the function's arguments into, computing with the unstable periods and candlestick settings of core; a nil core stands for talib.NewCore.

func (FuncInfo) OptInputs

func (f FuncInfo) OptInputs() []OptInputInfo

OptInputs returns the optional parameters, in call order.

func (FuncInfo) Outputs

func (f FuncInfo) Outputs() []OutputInfo

Outputs returns the outputs, in call order.

func (FuncInfo) String

func (f FuncInfo) String() string

String returns the function's name.

func (FuncInfo) UnstableID

func (f FuncInfo) UnstableID() (talib.FuncUnstId, bool)

UnstableID returns the function's unstable-period id, and false when it has none. It has one exactly when FuncUnstablePeriod is set.

type Group

type Group int32

Group is a function's category.

const (
	// GroupCycleIndicators: the Cycle Indicators group.
	GroupCycleIndicators Group = 0
	// GroupMathOperators: the Math Operators group.
	GroupMathOperators Group = 1
	// GroupMathTransform: the Math Transform group.
	GroupMathTransform Group = 2
	// GroupMomentumIndicators: the Momentum Indicators group.
	GroupMomentumIndicators Group = 3
	// GroupOverlapStudies: the Overlap Studies group.
	GroupOverlapStudies Group = 4
	// GroupPatternRecognition: the Pattern Recognition group.
	GroupPatternRecognition Group = 5
	// GroupPriceTransform: the Price Transform group.
	GroupPriceTransform Group = 6
	// GroupStatisticFunctions: the Statistic Functions group.
	GroupStatisticFunctions Group = 7
	// GroupVolatilityIndicators: the Volatility Indicators group.
	GroupVolatilityIndicators Group = 8
	// GroupVolumeIndicators: the Volume Indicators group.
	GroupVolumeIndicators Group = 9
)

The Group values.

func Groups

func Groups() []Group

Groups returns every group, in display-name order.

func (Group) String

func (g Group) String() string

String returns the group's display name, such as "Overlap Studies", spelled as C's TA_GroupString spells it.

type InputFlags

type InputFlags uint32

InputFlags are an input's flag word, InputInfo.Flags: the components a price input consumes (InPrice*), and the signs any input's bars may hold for the result to mean something (InPositive, InNegative, InZero). The values are C's TA_IN_*. Every input sets at least one sign, so test single bits, never compare the word whole. A sign is admitted only where a bar of it gives the formula's true value, not a guarded placeholder; an input admitting every sign sets all three. On a price input they speak for the open, high, low and close; volume is never negative. Declaration only: the data is not checked, and a bar outside them gets a successful call and a value that may have no meaning.

const (
	// InPriceOpen: the open price.
	InPriceOpen InputFlags = 0x00000001
	// InPriceHigh: the high price.
	InPriceHigh InputFlags = 0x00000002
	// InPriceLow: the low price.
	InPriceLow InputFlags = 0x00000004
	// InPriceClose: the close price.
	InPriceClose InputFlags = 0x00000008
	// InPriceVolume: the traded volume.
	InPriceVolume InputFlags = 0x00000010
	// InPriceOpenInterest: the open interest.
	InPriceOpenInterest InputFlags = 0x00000020
	// InPositive: positive values are admitted.
	InPositive InputFlags = 0x00000100
	// InNegative: negative values are admitted.
	InNegative InputFlags = 0x00000200
	// InZero: zero is admitted.
	InZero InputFlags = 0x00000400
)

The InputFlags bits.

type InputInfo

type InputInfo struct {
	// Kind says what the input carries.
	Kind InputKind
	// ParamName is the parameter's name, such as inReal or inPriceHLC.
	ParamName string
	// Flags are C's whole flag word for the input: for a price input the
	// components it consumes, and for every input its signs.
	Flags InputFlags
}

InputInfo is one input of a function.

func (InputInfo) Requires

func (i InputInfo) Requires(c PriceComponents) bool

Requires reports whether the input consumes every component of c.

type InputKind

type InputKind int32

InputKind says what an input carries. The values are C's TA_InputParameterType.

const (
	// InputPrice: a bundle of price components; [InputInfo.Flags] says which.
	InputPrice InputKind = 0
	// InputReal: one real series.
	InputReal InputKind = 1
	// InputInteger: one integer series.
	InputInteger InputKind = 2
)

The InputKind values.

func (InputKind) String

func (k InputKind) String() string

String returns the value's name, such as "Price".

type IntegerList

type IntegerList struct {
	// Values are the choices, in declaration order.
	Values []NamedValue
	// Default is the documented default: a value, not an index.
	Default int
}

IntegerList is a domain of named integer choices, such as an MA type.

type IntegerRange

type IntegerRange struct {
	// Min is the smallest accepted value.
	Min int
	// Max is the largest accepted value.
	Max int
	// Default is the documented default.
	Default int
	// SuggestedStart is where a parameter sweep starts.
	SuggestedStart int
	// SuggestedEnd is where a parameter sweep ends.
	SuggestedEnd int
	// SuggestedIncrement is a parameter sweep's step.
	SuggestedIncrement int
}

IntegerRange is a domain of integers within [Min, Max].

type NamedRealValue

type NamedRealValue struct {
	// Value is the value to pass.
	Value float64
	// Name is its name.
	Name string
}

NamedRealValue is one choice of a RealList.

type NamedValue

type NamedValue struct {
	// Value is the value to pass.
	Value int
	// Name is its name, such as "EMA".
	Name string
}

NamedValue is one choice of an IntegerList.

type OptInputFlags

type OptInputFlags uint32

OptInputFlags are the display hints of an optional parameter. The values are C's TA_OPTIN_*.

const (
	// OptIsPercent: the value is a percentage.
	OptIsPercent OptInputFlags = 0x00100000
	// OptIsDegree: the value is in degrees.
	OptIsDegree OptInputFlags = 0x00200000
	// OptIsCurrency: the value is in a currency.
	OptIsCurrency OptInputFlags = 0x00400000
	// OptAdvanced: advanced: a basic user interface may hide it.
	OptAdvanced OptInputFlags = 0x01000000
)

The OptInputFlags bits.

type OptInputInfo

type OptInputInfo struct {
	// Kind names the domain, and so the type Domain holds.
	Kind OptInputKind
	// ParamName is the parameter's name, such as optInTimePeriod.
	ParamName string
	// DisplayName is a short label for a user interface, such as "Time Period".
	DisplayName string
	// Hint is longer help text, or "" when there is none.
	Hint string
	// Flags are the display hints.
	Flags OptInputFlags
	// DefaultValue is the value an unset parameter takes, as C reports it in
	// defaultValue: the one [talib.IntegerDefault] or [talib.RealDefault]
	// selects.
	DefaultValue float64
	// Domain holds the values the parameter accepts: a [RealRange],
	// [RealList], [IntegerRange] or [IntegerList], as Kind says.
	Domain Domain
}

OptInputInfo is one optional parameter of a function.

type OptInputKind

type OptInputKind int32

OptInputKind is the domain of an optional parameter. The values are C's TA_OptInputParameterType.

const (
	// OptRealRange: a real within a range: the domain is a [RealRange].
	OptRealRange OptInputKind = 0
	// OptRealList: a real from a fixed set: the domain is a [RealList].
	OptRealList OptInputKind = 1
	// OptIntegerRange: an integer within a range: the domain is an [IntegerRange].
	OptIntegerRange OptInputKind = 2
	// OptIntegerList: an integer from a fixed set: the domain is an [IntegerList].
	OptIntegerList OptInputKind = 3
)

The OptInputKind values.

func (OptInputKind) String

func (k OptInputKind) String() string

String returns the value's name, such as "RealRange".

type OutputFlags

type OutputFlags uint32

OutputFlags say how an output is drawn and which values it takes. The values are C's TA_OUT_*. A pattern output writes 0 or a sign times a level: the sign flags give its signs, the level flags its levels (100 always).

const (
	// OutLine: draw as a continuous line.
	OutLine OutputFlags = 0x00000001
	// OutDotLine: draw as a dotted line.
	OutDotLine OutputFlags = 0x00000002
	// OutDashLine: draw as a dashed line.
	OutDashLine OutputFlags = 0x00000004
	// OutDot: draw as unconnected dots.
	OutDot OutputFlags = 0x00000008
	// OutHistogram: draw as a histogram.
	OutHistogram OutputFlags = 0x00000010
	// OutPatternBool: two states: 0 is no pattern, non-zero a pattern.
	OutPatternBool OutputFlags = 0x00000020
	// OutPatternBullBear: the sign is a call: positive bullish, negative bearish.
	OutPatternBullBear OutputFlags = 0x00000040
	// OutPatternConfirm: level 200 occurs too: this bar confirms the output's most
	// recent earlier pattern.
	OutPatternConfirm OutputFlags = 0x00000080
	// OutPositive: positive values occur.
	OutPositive OutputFlags = 0x00000100
	// OutNegative: negative values occur.
	OutNegative OutputFlags = 0x00000200
	// OutZero: zero occurs; on a pattern output, no pattern on this bar. An output
	// setting any of the three sign flags declares all its signs; one setting none
	// declares nothing.
	OutZero OutputFlags = 0x00000400
	// OutUpperLimit: an upper band or limit line.
	OutUpperLimit OutputFlags = 0x00000800
	// OutLowerLimit: a lower band or limit line.
	OutLowerLimit OutputFlags = 0x00001000
	// OutDisplayShift: a chart draws it ahead of or behind the bar that computed
	// it, by the bars [ParamHolder.DisplayShift] reports. The values are never
	// shifted.
	OutDisplayShift OutputFlags = 0x00004000
	// OutPatternWeak: level 80 occurs too: a weaker form of the pattern, on the
	// same bar.
	OutPatternWeak OutputFlags = 0x00008000
	// OutBarIndex: the value is an absolute index into the input slices.
	OutBarIndex OutputFlags = 0x00010000
	// OutSegmented: a line whose segments restart wherever the function's integer
	// output changes value: never connect across a change.
	OutSegmented OutputFlags = 0x00020000
	// OutPatternColor: the sign is the color of the bar the value is for: positive
	// when close >= open, negative otherwise.
	OutPatternColor OutputFlags = 0x00040000
)

The OutputFlags bits.

type OutputInfo

type OutputInfo struct {
	// Kind says whether the output is real or integer.
	Kind OutputKind
	// ParamName is the parameter's name, such as outRealUpperBand.
	ParamName string
	// Flags are the drawing and value hints.
	Flags OutputFlags
}

OutputInfo is one output of a function.

type OutputKind

type OutputKind int32

OutputKind says what an output carries. The values are C's TA_OutputParameterType.

const (
	// OutputReal: a []float64 output.
	OutputReal OutputKind = 0
	// OutputInteger: an []int32 output.
	OutputInteger OutputKind = 1
)

The OutputKind values.

func (OutputKind) String

func (k OutputKind) String() string

String returns the value's name, such as "Real".

type ParamHolder

type ParamHolder struct {
	// contains filtered or unexported fields
}

ParamHolder binds the arguments of a function chosen at run time, then calls it: the counterpart of C's TA_ParamHolder. Obtain one from FuncInfo.NewCall.

Each setter checks its argument against the function's description before it writes, so a rejected call leaves the holder as it was. A rejection is talib.BadParam for an index out of range or a value missing or out of reach, and talib.InvalidParamHolderType for a slot of another kind. An optional parameter left unset takes its default.

A ParamHolder belongs to one goroutine.

func (*ParamHolder) Call

func (h *ParamHolder) Call(startIdx, endIdx int) (talib.OutRange, error)

Call runs the function over bars startIdx through endIdx through its method on talib.Core, which returns exactly what a direct call does. An unbound input is talib.InputNotAllInitialize and an unbound output talib.OutputNotAllInitialize, and the function does not run.

func (*ParamHolder) Core

func (h *ParamHolder) Core() *talib.Core

Core returns the settings the call computes with.

func (*ParamHolder) DisplayShift

func (h *ParamHolder) DisplayShift(outputIdx int) (int, error)

DisplayShift returns how many bars ahead (positive) or behind (negative) of the bar that computed it a chart draws output outputIdx, for the optional parameters bound so far, through the function's DisplayShift method on talib.Core, and that method's error: talib.BadParam for a parameter out of range or an index that names no output. It is 0 for an output without OutDisplayShift. Inputs and outputs need not be bound.

func (*ParamHolder) Info

func (h *ParamHolder) Info() FuncInfo

Info returns the function the holder calls.

func (*ParamHolder) Lookback

func (h *ParamHolder) Lookback() (int, error)

Lookback returns the function's lookback for the optional parameters bound so far, through its Lookback method on talib.Core, and that method's error. Inputs and outputs need not be bound.

func (*ParamHolder) SetInput

func (h *ParamHolder) SetInput(idx int, series []float64) error

SetInput binds real input idx. The series is not copied.

func (*ParamHolder) SetIntInput

func (h *ParamHolder) SetIntInput(idx int, series []int32) error

SetIntInput binds integer input idx. The series is not copied.

func (*ParamHolder) SetIntOutput

func (h *ParamHolder) SetIntOutput(idx int, out []int32) error

SetIntOutput binds integer output idx: the slice the call writes it into.

func (*ParamHolder) SetOptInputInteger

func (h *ParamHolder) SetOptInputInteger(idx, value int) error

SetOptInputInteger binds optional parameter idx, of an integer domain. Its range is checked when the function runs; talib.IntegerDefault selects the default.

func (*ParamHolder) SetOptInputMAType

func (h *ParamHolder) SetOptInputMAType(idx int, value talib.MAType) error

SetOptInputMAType binds optional parameter idx, a moving-average type. A parameter of another domain, a period included, is talib.InvalidParamHolderType.

func (*ParamHolder) SetOptInputReal

func (h *ParamHolder) SetOptInputReal(idx int, value float64) error

SetOptInputReal binds optional parameter idx, of a real domain. Its range is checked when the function runs; talib.RealDefault selects the default.

func (*ParamHolder) SetOutput

func (h *ParamHolder) SetOutput(idx int, out []float64) error

SetOutput binds real output idx: the slice the call writes it into.

func (*ParamHolder) SetPriceInput

func (h *ParamHolder) SetPriceInput(idx int, p PriceInput) error

SetPriceInput binds price input idx. Every component the input consumes must be present; one it does not consume is accepted and ignored. The slices are not copied.

func (*ParamHolder) SetPriceInputComponent

func (h *ParamHolder) SetPriceInputComponent(idx int, c PriceComponents, series []float64) error

SetPriceInputComponent binds one component of price input idx; c names exactly one component, such as PriceHigh. A component the input does not consume is accepted and ignored. The series is not copied.

type PriceComponents

type PriceComponents uint32

PriceComponents are price components, as InputInfo.Requires and ParamHolder.SetPriceInputComponent take them. The values are C's TA_IN_PRICE_*, the price bits of InputFlags.

const (
	// PriceOpen: the open price.
	PriceOpen PriceComponents = 0x00000001
	// PriceHigh: the high price.
	PriceHigh PriceComponents = 0x00000002
	// PriceLow: the low price.
	PriceLow PriceComponents = 0x00000004
	// PriceClose: the close price.
	PriceClose PriceComponents = 0x00000008
	// PriceVolume: the traded volume.
	PriceVolume PriceComponents = 0x00000010
	// PriceOpenInterest: the open interest.
	PriceOpenInterest PriceComponents = 0x00000020
)

The PriceComponents bits.

type PriceInput

type PriceInput struct {
	// Open is the open prices.
	Open []float64
	// High is the high prices.
	High []float64
	// Low is the low prices.
	Low []float64
	// Close is the close prices.
	Close []float64
	// Volume is the volumes.
	Volume []float64
	// OpenInterest is the open interest.
	OpenInterest []float64
}

PriceInput holds the components of a price input. Leave nil the ones the input does not consume.

type RealList

type RealList struct {
	// Values are the choices, in declaration order.
	Values []NamedRealValue
	// Default is the documented default.
	Default float64
}

RealList is a domain of named real choices. No function declares one; a switch over a Domain still has to account for it.

type RealRange

type RealRange struct {
	// Min is the smallest accepted value.
	Min float64
	// Max is the largest accepted value.
	Max float64
	// Precision is how many decimals a user interface offers.
	Precision int
	// Default is the documented default.
	Default float64
	// SuggestedStart is where a parameter sweep starts.
	SuggestedStart float64
	// SuggestedEnd is where a parameter sweep ends.
	SuggestedEnd float64
	// SuggestedIncrement is a parameter sweep's step.
	SuggestedIncrement float64
}

RealRange is a domain of reals within [Min, Max].

Jump to

Keyboard shortcuts

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