Documentation ¶
Overview ¶
Package ta offers technical analysis functions for price series data.
Index ¶
- Constants
- func Close(price market.Kline) float64
- func CrossDown(series []float64, x float64) bool
- func CrossUp(series []float64, x float64) bool
- func HL2(price market.Kline) float64
- func HLC3(price market.Kline) float64
- func Lookback[T any](series []T, n int) T
- func Median(v []float64) float64
- func OHLC4(price market.Kline) float64
- func Peak(series []float64, delta float64) bool
- func Slope(t1, t2 float64) int
- func Valley(series []float64, delta float64) bool
- func Window[T any](series []T, n int) []T
- func WindowAppend[T any](series []T, n int, v T) []T
- type ALMA
- type Indicator
- type MMI
- type MockIndicator
- type Osc
- type PriceSelector
- type SD
- type StubIndicator
- type VWAP
- type VolumeLevel
- type VolumeProfile
Constants ¶
const ( // DefaultALMAOffset is the default offset for the ALMA indicator. DefaultALMAOffset = 0.85 // DefaultALMASigma is the default sigma for the ALMA indicator. DefaultALMASigma = 6 )
const DefaultValueAreaPercentage = 0.68
DefaultValueAreaPercentage is the percentage of the total volume used to calculate the value area.
Variables ¶
This section is empty.
Functions ¶
func CrossDown ¶
CrossDown returns true if the latest series values cross below the given value. The series must be in chronological order, with the earliest value at index 0. The series must have at least 2 values
func CrossUp ¶
CrossUp returns true if the latest series values cross above the given value. The series must be in chronological order, with the earliest value at index 0. The series must have at least 2 values
func Lookback ¶
Lookback returns a value from series at n index ago. Series must be in chronological order, with the earliest value at slice index 0. n = 0 returns the latest value. n = 1 returns the value before the latest etc.
func Peak ¶
Peak returns true if the latest values in the series have formed a peak. Series must be in chronological order, with the earliest value at slice index 0. Series must have at least 3 values. Arg delta is the threshold change in the series values required to detect a peak.
func Slope ¶
Slope indicates the direction between two points. t1 is the first point, t2 is the second point. Returns 1 for up, -1 for down, 0 for flat.
func Valley ¶
Valley returns true if the latest values in the series have formed a valley. Series must be in chronological order, with the earliest value at slice index 0. Series must have at least 3 values. Arg delta is the threshold change in the series values required to detect a valley.
func Window ¶
Window returns a copied slice of series starting at n index ago. Semantics of n argument are the same as Lookback function.
func WindowAppend ¶
WindowAppend appends a value to the end of the series and slices it to the window starting at n index ago. Semantics of n argument are the same as Window and Lookback functions.
Types ¶
type ALMA ¶
type ALMA struct { Length int Offset float64 Sigma float64 // contains filtered or unexported fields }
ALMA is a modern low lag moving average. Ported from https://www.tradingview.com/pine-script-reference/#fun_alma
func NewALMAWithSigma ¶
NewALMAWithSigma creates a new ALMA indicator with the given offset and sigma.
type Indicator ¶
type Indicator[T any] interface { // Update the indicator with new inputs (typically a price series). Update(v ...T) error // Value returns the latest value of the indicator. Value() float64 // History returns all the historical indicator values (including the latest value). History() []float64 // Valid returns true if the indicator is valid. Valid() bool }
Indicator is the interface for all technical analysis functions.
type MMI ¶
type MMI struct { // Length is the number of values to use for the calculation. Length int // Smoother is the indicator used to smooth the MMI. Smoother Indicator[float64] // contains filtered or unexported fields }
MMI (Market Meaness Index) is a statistical measure between 0 - 100 that indicates if the series exhibits serial correlation (trendiness). Reference: https://financial-hacker.com/the-market-meanness-index/.
func NewMMI ¶
NewMMI returns a new MMI indicator with a default ALMA smoother. The smoothing length is the same as the given MMI length.
func NewMMIWithSmoother ¶
NewMMIWithSmoother returns a new MMI indicator with the given smoother.
type MockIndicator ¶
MockIndicator is a mock implementation of the Indicator interface.
func (*MockIndicator) History ¶
func (ind *MockIndicator) History() []float64
History returns the history of the indicator.
func (*MockIndicator) Update ¶
func (ind *MockIndicator) Update(v ...float64) error
Update updates the indicator with the next value(s).
func (*MockIndicator) Valid ¶
func (ind *MockIndicator) Valid() bool
Valid returns true if the indicator has enough data to be calculated.
func (*MockIndicator) Value ¶
func (ind *MockIndicator) Value() float64
Value returns the current value of the indicator.
type Osc ¶
type Osc struct { // Fast is the fast moving average indicator. Fast Indicator[float64] // Slow is the slow moving average indicator. Slow Indicator[float64] // contains filtered or unexported fields }
Osc is a composite of a fast and slow moving average indicator. Osc value = fast value minus slow value. Osc is not normalized and has an unbounded range.
type PriceSelector ¶
PriceSelector is a selector that returns a price value for the given kline.
type SD ¶
type SD struct { // Length is the number of values to use in the calculation. Length int // Factor is the factor to multiply the standard deviation by. Factor float64 // contains filtered or unexported fields }
SD is a sample standard deviation indicator.
func NewSDWithFactor ¶
NewSDWithFactor returns a new SD indicator with the given factor.
type StubIndicator ¶
type StubIndicator struct { // Values is the history of the indicator. Values []float64 // IsValid is the validity of the indicator. IsValid bool }
StubIndicator is a test double for an indicator.
func (*StubIndicator) History ¶
func (ind *StubIndicator) History() []float64
History returns the history of the indicator.
func (*StubIndicator) Update ¶
func (ind *StubIndicator) Update(v ...float64) error
Update is not implemented.
func (*StubIndicator) Value ¶
func (ind *StubIndicator) Value() float64
Value returns the latest value in Values
type VWAP ¶
type VWAP struct {
// contains filtered or unexported fields
}
VWAP is a volume weighted average price.
type VolumeLevel ¶
type VolumeLevel struct { // Price is the market price, typically the high/low average of the kline. Price float64 // Volume is the total buy and sell volume at the price. Volume float64 }
VolumeLevel is a price and volume pair used to build a volume profile.
type VolumeProfile ¶
type VolumeProfile struct { // Bins is the histogram bins. Bins []float64 // Hist is the histogram values. Hist []float64 // POC is the point of control. POC float64 // VAH is the value area high. VAH float64 // VAL is the value area low. VAL float64 // High is the highest price in the profile. High float64 // Low is the lowest price in the profile. Low float64 }
VolumeProfile is a histogram of market price and volume. Intent is to show the price points with most volume during a period. The profile gives key features such as:
Point of control (POC)
Value area high (VAH)
Value area low (VAL)
Session High ¶
Session Low
func NewVolumeProfile ¶
func NewVolumeProfile(nBins int, levels []VolumeLevel) *VolumeProfile
NewVolumeProfile creates a new profile for the price and volume series given by levels. nBins is the number of bins to use for the profile histogram.
func NewVolumeProfileFixedBinWidth ¶ added in v0.0.20
func NewVolumeProfileFixedBinWidth(binWidth float64, levels []VolumeLevel) *VolumeProfile
NewVolumeProfileFixedBinWidth creates a new volume profile with a variable number of bins dictated by binWidth. Returns nil if binWidth is not positive.