indicator

package module
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: AGPL-3.0 Imports: 5 Imported by: 5

README

indicator

The trade indicator.

Indicator Support

indicator support
EMA Yes
SMA Yes
SMMA Yes
Stoch No Test
StochRSI Yes
ATR Yes
ADX Yes

Quick Start: OHLC Indicators

You can quickly create OHLC-based indicators (such as ATR, ADX) using NewOHLCIndicator:

atr, err := indicator.NewOHLCIndicator("ATR", 14)
adx, err := indicator.NewOHLCIndicator("ADX", 14)
if err != nil {
    panic(err)
}
for _, candle := range candles {
    atr.UpdateOHLC(candle.Open, candle.High, candle.Low, candle.Close)
    adx.UpdateOHLC(candle.Open, candle.High, candle.Low, candle.Close)
}
fmt.Println("ATR:", atr.Result())
fmt.Println("ADX:", adx.Result())
fmt.Println("+DI:", adx.PlusDI(), "-DI:", adx.MinusDI())

Currently supported: ATR, ADX. More OHLC indicators can be added easily.

Note:

  • For accurate results, always use UpdateOHLC(open, high, low, close).
  • wilderAverage is the internal smoothing engine for ATR/ADX:
    • Warm-up: uses SMA to initialize the first smoothed value
    • Running: next = (prev*(period-1) + current) / period
  • During warm-up, ATR/ADX may return 0 until enough data arrives.
  • Both indicators also support the simple Update(price) interface (close-only fallback).

Cheers to

Some indicator refer to Gekko

Some indicator refer to tradingview wiki StochRSI

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ExtraIndicators = map[string]NewCommonIndicatorFunc{}
)

Functions

func RegisterIndicator

func RegisterIndicator(name string, fn NewCommonIndicatorFunc)

Types

type ADX added in v1.1.3

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

ADX Average Directional Index. Use UpdateOHLC for standard ADX, or Update for close-only fallback.

func NewADX added in v1.1.3

func NewADX(winLen int) *ADX

func (*ADX) DX added in v1.1.3

func (a *ADX) DX() float64

func (*ADX) FastResult added in v1.1.3

func (a *ADX) FastResult() float64

func (*ADX) MinusDI added in v1.1.3

func (a *ADX) MinusDI() float64

func (*ADX) PlusDI added in v1.1.3

func (a *ADX) PlusDI() float64

func (*ADX) Result added in v1.1.3

func (a *ADX) Result() float64

func (*ADX) SlowResult added in v1.1.3

func (a *ADX) SlowResult() float64

func (*ADX) Update added in v1.1.3

func (a *ADX) Update(values ...float64) error

func (*ADX) UpdateOHLC added in v1.1.3

func (a *ADX) UpdateOHLC(open, high, low, close float64)

type ATR added in v1.1.3

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

ATR Average True Range Use UpdateOHLC for standard ATR, or Update for close-only fallback.

func NewATR added in v1.1.3

func NewATR(winLen int) *ATR

func (*ATR) Result added in v1.1.3

func (a *ATR) Result() float64

func (*ATR) TR added in v1.1.3

func (a *ATR) TR() float64

func (*ATR) Update added in v1.1.3

func (a *ATR) Update(values ...float64) error

func (*ATR) UpdateOHLC added in v1.1.3

func (a *ATR) UpdateOHLC(open, high, low, close float64)

type Boll

type Boll struct {
	*SMA
	// contains filtered or unexported fields
}

func NewBoll

func NewBoll(winLen, k int) *Boll

func (*Boll) Bottom

func (b *Boll) Bottom() float64

func (*Boll) Cal

func (b *Boll) Cal()

func (*Boll) Indicator

func (b *Boll) Indicator() map[string]float64

func (*Boll) Result

func (b *Boll) Result() float64

func (*Boll) Top

func (b *Boll) Top() float64

func (*Boll) Update

func (b *Boll) Update(values ...float64) error

type CommonIndicator

type CommonIndicator interface {
	Indicator
	Indicator() map[string]float64
}

CommonIndicator

func NewCommonIndicator

func NewCommonIndicator(name string, params ...int) (ind CommonIndicator, err error)

type CrossTool

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

func NewCrossTool

func NewCrossTool(crosser Crosser) *CrossTool

func (*CrossTool) IsCrossDown

func (ct *CrossTool) IsCrossDown() bool

func (*CrossTool) IsCrossUp

func (ct *CrossTool) IsCrossUp() bool

func (*CrossTool) Update

func (ct *CrossTool) Update(values ...float64) error

type Crosser

type Crosser interface {
	Updater
	SlowResult() float64
	FastResult() float64
}

type EMA

type EMA struct {
	MABase
	// contains filtered or unexported fields
}

func NewEMA

func NewEMA(winLen int) *EMA

func (*EMA) Update

func (e *EMA) Update(values ...float64) error

type Indicator

type Indicator interface {
	Updater
	Result() float64
}

type JsonIndicator

type JsonIndicator struct {
	CommonIndicator
}

func NewJsonIndicator

func NewJsonIndicator(m CommonIndicator) *JsonIndicator

func (*JsonIndicator) MarshalJSON

func (j *JsonIndicator) MarshalJSON() (buf []byte, err error)

type MABase

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

func (*MABase) Result

func (m *MABase) Result() float64

type MACD

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

func NewMACD

func NewMACD(short, long, signal int) *MACD

func NewMACDWithSMA

func NewMACDWithSMA(short, long, signal int) *MACD

NewMACDWithSMA macd signal line with simple ma

func (*MACD) DEA

func (ma *MACD) DEA() float64

func (*MACD) DIF

func (ma *MACD) DIF() float64

func (*MACD) FastResult

func (ma *MACD) FastResult() float64

func (*MACD) Result

func (ma *MACD) Result() float64

func (*MACD) SlowResult

func (ma *MACD) SlowResult() float64

func (*MACD) Update

func (ma *MACD) Update(values ...float64) error

type MAGroup

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

func NewMAGroup

func NewMAGroup(fast, slow Indicator) *MAGroup

func (*MAGroup) FastResult

func (mg *MAGroup) FastResult() float64

func (*MAGroup) SlowResult

func (mg *MAGroup) SlowResult() float64

func (*MAGroup) Update

func (mg *MAGroup) Update(values ...float64) error

type Mixed

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

func NewMixed

func NewMixed(indicator Indicator, crossIndicator Crosser) *Mixed

func (*Mixed) FastResult

func (m *Mixed) FastResult() float64

func (*Mixed) Indicator

func (m *Mixed) Indicator() map[string]float64

func (*Mixed) IsCrossDown

func (m *Mixed) IsCrossDown() bool

func (*Mixed) IsCrossUp

func (m *Mixed) IsCrossUp() bool

func (*Mixed) Result

func (m *Mixed) Result() float64

func (*Mixed) SetOHLC added in v1.1.8

func (m *Mixed) SetOHLC(isOHLC bool) *Mixed

func (*Mixed) SlowResult

func (m *Mixed) SlowResult() float64

func (*Mixed) SupportResult

func (m *Mixed) SupportResult() bool

func (*Mixed) SupportSlowFast

func (m *Mixed) SupportSlowFast() bool

func (*Mixed) Update

func (m *Mixed) Update(values ...float64) error

type NewCommonIndicatorFunc

type NewCommonIndicatorFunc func(params ...int) (CommonIndicator, error)

type RSI

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

func NewRSI

func NewRSI(winLen int) *RSI

func (*RSI) Result

func (r *RSI) Result() float64

func (*RSI) Update

func (r *RSI) Update(values ...float64) error

type SMA

type SMA struct {
	MABase
	// contains filtered or unexported fields
}

func NewSMA

func NewSMA(winLen int) *SMA

func (*SMA) Update

func (s *SMA) Update(values ...float64) error

type SMMA

type SMMA struct {
	MABase
	// contains filtered or unexported fields
}

SMMA Smoothed Moving Average (SMMA)

func NewSMMA

func NewSMMA(winLen int) *SMMA

func (*SMMA) Update

func (sm *SMMA) Update(values ...float64) error

type Stoch

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

Stoch just test with StochRSI

func NewStoch

func NewStoch(winLen, periodK, periodD int) *Stoch

func (*Stoch) DResult

func (s *Stoch) DResult() float64

func (*Stoch) KResult

func (s *Stoch) KResult() float64

func (*Stoch) Result

func (s *Stoch) Result() float64

func (*Stoch) Update

func (s *Stoch) Update(values ...float64) error

type StochRSI

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

StochRSI result test with aicoin's bitmex data maybe it's difference with different website

func NewStochRSI

func NewStochRSI(winLen, rsiWinLen, k, d int) *StochRSI

func (*StochRSI) DResult

func (sr *StochRSI) DResult() float64

func (*StochRSI) FastResult

func (sr *StochRSI) FastResult() float64

func (*StochRSI) KResult

func (sr *StochRSI) KResult() float64

func (*StochRSI) Result

func (sr *StochRSI) Result() float64

func (*StochRSI) SlowResult

func (sr *StochRSI) SlowResult() float64

func (*StochRSI) Update

func (sr *StochRSI) Update(values ...float64) error

type Updater

type Updater interface {
	Update(price ...float64) error
}

Jump to

Keyboard shortcuts

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