banta

package module
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 9 Imported by: 12

README

BanTA Technical Analysis Library

中文文档
banta is a high-performance technical analysis indicator library that supports both state-caching and parallel computation modes. It aims to provide a highly flexible, high-performance, and user-friendly indicator framework.

  • State-Caching Mode: Updates and caches on each candle, eliminating the need to recalculate historical data. Indicator results are globally reused, similar to TradingView.
  • Parallel Computation Mode: Computes all candles at once without caching. New candles require a full recalculation, similar to TA-Lib.
  • NaN Compatibility: Intelligently skips NaN values in input data, resuming calculations with the previous state.
  • Rigorous Testing: Each indicator is validated with unit tests under various conditions and compared against results from common indicator libraries.
  • Lightweight & Dependency-Free: Pure Go implementation with zero external dependencies.
  • Python Support: Packaged as the bbta module via gopy, ready to be imported and used directly in Python.

Supported Indicators

Consistency Comparison with Common Indicator Platforms
banta MyTT TA-lib Class TA-lib Metastock Pandas-TA TradingView
AvgPrice
Sum
SMA T1
EMA T1 T1 T2
EMABy1 T1 T2 T2 T3
RMA -- -- -- T1 --
VWMA -- -- --
WMA
HMA -- -- --
TR -- --
ATR T1 T2 T3
MACD T1 T2 T1 T3
RSI T1 T2 T3
KDJ T1 T2 T1 T3
Stoch -- --
BBANDS
Aroon -- T1
ADX -- T1 T2
ADXBy1 -- T1 T1 T2
PluMinDI -- -- --
PluMinDM -- -- --
ROC --
TNR/ER -- -- -- -- --
CCI
CMF -- -- --
KAMA -- T1 ✔~
WillR --
StochRSI -- ✔~
MFI
RMI -- -- -- -- ✔~
CTI -- -- -- T1
LinReg -- -- -- ?
CMO -- T1
CMOBy1 -- T1 T1 T1
CHOP -- -- -- T1
ALMA -- -- -- T1
Stiffness -- -- -- --
PercentRank -- -- -- -- ✔~
CRSI -- -- -- -- ✔~
CRSIBy1 -- community -- -- --
DV -- -- -- -- --
UTBot -- -- -- --
STC -- -- -- --
--  This platform does not have the indicator  
✔  Consistent with this platform's results  
✔~ Mostly consistent with this platform's results (minor deviations)  
Ti Inconsistent with this platform's results  

How to Use (State-Caching Mode)

import (  
	"fmt"  
	ta "github.com/banbox/banta"  
)  

var envMap = make(map[string]*ta.BarEnv)  

func OnBar(symbol string, timeframe string, bar *ta.Kline) {  
	envKey := fmt.Sprintf("%s_%s", symbol, timeframe)  
	e, ok := envMap[envKey]  
	if !ok {  
		e = &ta.BarEnv{  
			TimeFrame: timeframe,  
			BarNum:    1,  
		}  
		envMap[envKey] = e  
	}  
	e.OnBar(bar)  
	ma5 := ta.SMA(e.Close, 5)  
	ma30 := ta.SMA(e.Close, 30)  
	atr := ta.ATR(e.High, e.Low, e.Close, 14).Get(0)  
	xnum := ta.Cross(ma5, ma30)  
	if xnum == 1 {  
		// ma5 cross up ma30  
		curPrice := e.Close.Get(0) // or bar.Close  
		stopLoss := curPrice - atr  
		fmt.Printf("open long at %f, stoploss: %f", curPrice, stopLoss)  
	} else if xnum == -1 {  
		// ma5 cross down ma30  
		curPrice := e.Close.Get(0)  
		fmt.Printf("close long at %f", curPrice)  
	}  
	kdjRes := ta.KDJ(e.High, e.Low, e.Close, 9, 3, 3).Cols  
	k, d := kdjRes[0], kdjRes[1]  
}  
Core Concept

Traditional technical analysis libraries like TA-Lib and Pandas-TA are widely used and highly optimized for performance, making them extremely fast when computing hundreds or thousands of candles at once.
However, when your trading bot uses these libraries in live trading, every new candle requires passing in hundreds of historical candles. If you're running multiple symbols or operating on 1-minute or even 1-second timeframes, the computational delay can become unbearable.
Many are familiar with TradingView, which uses Pine Script—an event-driven technical analysis engine. It doesn't recalculate historical candles upon receiving a new one but instead reuses cached results.
This is the philosophy behind BanTA: event-driven computation, processing each candle as it arrives while leveraging cached results.

How State Caching Works in BanTA

In BanTA, state caching revolves around the Series sequence type. Most return values are sequences, and the Series struct includes a Data []float64 field that records the indicator's values across candles.
For example, e.Close is the closing price sequence, and e.Close.Get(0) retrieves the current closing price as a float64.
Calculating a moving average is straightforward: ma5 := ta.SMA(e.Close, 5), which returns another sequence.
Some indicators like KDJ return multiple fields: kdjRes := ta.KDJ(e.High, e.Low, e.Close, 9, 3, 3).Cols, where Cols contains an array of sequences (e.g., K and D lines).

How to Use (Parallel Computation)

import (  
	"github.com/banbox/banta/tav"  
)  

func main(){  
	highArr := []float64{1.01, 1.01, 1.02, 0.996, 0.98, 0.993, 0.99, 1.0, 1.02}  
    lowArr := []float64{0.99, 1.0, 1.0, 0.98, 0.965, 0.98, 0.98, 0.984, 1.0}  
	closeArr := []float64{1.0, 1.01, 1.0, 0.99, 0.97, 0.981, 0.988, 0.992, 1.002}  
	sma := tav.SMA(closeArr, 5)  
    ma30 := tav.SMA(closeArr, 30)  
    atr := tav.ATR(highArr, lowArr, closeArr, 14)  
    xArr := tav.Cross(ma5, ma30)  
}  
Note

For research purposes, we recommend using parallel computation to compute indicators in bulk. For live trading or event-driven backtesting, state-cached indicators offer higher efficiency.

Python Installation

pip install bbta  

Only supports Python 8 and above. Currently not compatible with Python 13 on macOS and Windows.

Python Usage (State-Caching Mode)

from bbta import ta

# 1. Create an environment
# BarEnv manages state; create one for each time frame/trading pair.
env = ta.BarEnv(TimeFrame="1m")

# 2. Prepare candle data
# (timestamp ms, open, high, low, close, volume)
klines = [
    (1672531200000, 100, 102, 99, 101, 1000), (1672531260000, 101, 103, 100, 102, 1200),
    (1672531320000, 102, 105, 101, 104, 1500), (1672531380000, 104, 105, 103, 103, 1300),
    (1672531440000, 103, 104, 102, 103, 1100), (1672531500000, 103, 106, 103, 105, 1600),
    (1672531560000, 105, 107, 104, 106, 1800), (1672531620000, 106, 106, 102, 103, 2000),
    (1672531680000, 103, 104, 101, 102, 1700), (1672531740000, 102, 103, 100, 101, 1400),
]

# 3. Simulate candle pushes
# In live trading, call OnBar for each new candle.
for kline in klines:
    ts, o, h, l, c, v = kline
    env.OnBar(ts, o, h, l, c, v, 0)

    # 4. Calculate indicators
    ma5 = ta.Series(ta.SMA(env.Close, 5))
    ma30 = ta.Series(ta.SMA(env.Close, 30))

    # Get the latest value
    ma5_val = ma5.Get(0)
    ma30_val = ma30.Get(0)
    print(f"Close={c:.2f}, MA5={ma5_val:.2f}, MA30={ma30_val:.2f}")

## Python Usage (Parallel Computation)
```python
from bbta import tav, go

# 1. Prepare data
# Functions in parallel mode accept go.Slice_float64 type.
# We can create it from a Python list.
high_py = [102.0, 103.0, 105.0, 105.0, 104.0, 106.0, 107.0, 106.0, 104.0, 103.0]
low_py = [99.0, 100.0, 101.0, 103.0, 102.0, 103.0, 104.0, 102.0, 101.0, 100.0]
close_py = [101.0, 102.0, 104.0, 103.0, 103.0, 105.0, 106.0, 103.0, 102.0, 101.0]

high = go.Slice_float64(high_py)
low = go.Slice_float64(low_py)
close = go.Slice_float64(close_py)

# 2. Compute all indicators at once
# The result is also a go.Slice type.
ma5 = tav.SMA(close, 5)
atr = tav.ATR(high, low, close, 14)

# 3. View the results
# You can convert it to a Python list to view.
print(f"Close: {list(close)[-5:]}")
print(f"MA5:   {[f'{x:.2f}' for x in list(ma5)[-5:]]}")
print(f"ATR:   {[f'{x:.2f}' for x in list(atr)[-5:]]}")

# For indicators with multiple return values, like KDJ
kdj_result = tav.KDJ(high, low, close, 9, 3, 3)
k_line = kdj_result[0]
d_line = kdj_result[1]
j_line = kdj_result[2]
print(f"K-line: {[f'{x:.2f}' for x in list(k_line)[-5:]]}")

Documentation

Index

Constants

View Source
const (
	MinPenLen = 5
	CLInit    = 0 // 尚未确认有效
	CLValid   = 1 // 确认有效,尚未完成
	CLDone    = 2 // 确认有效,已完成,不会再改

	ParseLevelPen    = 1
	ParseLevelSeg    = 2
	ParseLevelCentre = 3
	ParseLevelTrend  = 4

	DefMaxPen = 1000 // 默认保存的最大笔数量
)
View Source
const (
	EvtNew    = 1
	EvtChange = 2
	EvtRemove = 3
)
View Source
const (
	SecsMin  = 60
	SecsHour = SecsMin * 60
	SecsDay  = SecsHour * 24
	SecsWeek = SecsDay * 7
	SecsMon  = SecsDay * 30
	SecsQtr  = SecsMon * 3
	SecsYear = SecsDay * 365
)

Variables

View Source
var (
	ErrInvalidSeriesVal = errors.New("invalid val for Series")
)

Functions

func Aroon added in v0.1.3

func Aroon(high *Series, low *Series, period int) (*Series, *Series, *Series)

Aroon 阿隆指标

Reflects the distance between the highest price and the lowest price within a certain period of time. 反映了一段时间内出现最高价和最低价距离当前时间的远近。

AroonUp: (period - HighestBar(high, period+1)) / period * 100

AroonDn: (period - LowestBar(low, period+1)) / period * 100

Osc: AroonUp - AroonDn

return [AroonUp, Osc, AroonDn]

func BBANDS

func BBANDS(obj *Series, period int, stdUp, stdDn float64) (*Series, *Series, *Series)

BBANDS Bollinger Bands 布林带指标

period: 20, stdUp: 2, stdDn: 2

return [upper, mid, lower]

func Cross deprecated

func Cross(obj1 *Series, obj2 interface{}) int

Deprecated: use Series.Cross instead

func HeikinAshi

func HeikinAshi(e *BarEnv) (*Series, *Series, *Series, *Series)

HeikinAshi return [open,high,low,close]

func KDJ

func KDJ(high *Series, low *Series, close *Series, period int, sm1 int, sm2 int) (*Series, *Series, *Series)

KDJ alias: stoch indicator;

period: 9, sm1: 3, sm2: 3

return (K, D, RSV)

func KDJBy

func KDJBy(high *Series, low *Series, close *Series, period int, sm1 int, sm2 int, maBy string) (*Series, *Series, *Series)

KDJBy alias: talib stoch indicator;

period: 9, sm1: 3, sm2: 3

return (K, D, RSV)

func MACD

func MACD(obj *Series, fast int, slow int, smooth int) (*Series, *Series)

MACD

Internationally, init_type=0 is used, while MyTT and China mainly use init_type=1 国外主流使用init_type=0,MyTT和国内主要使用init_type=1

fast: 12, slow: 26, smooth: 9

return [macd, signal]

func MACDBy

func MACDBy(obj *Series, fast int, slow int, smooth int, initType int) (*Series, *Series)

func ParseTimeFrame added in v0.3.5

func ParseTimeFrame(timeframe string) (int, error)

func PluMinDI added in v0.1.8

func PluMinDI(high *Series, low *Series, close *Series, period int) (*Series, *Series)

PluMinDI

suggest period: 14

return [plus di, minus di]

func PluMinDM added in v0.1.8

func PluMinDM(high *Series, low *Series, close *Series, period int) (*Series, *Series)

PluMinDM

suggest period: 14

return [Plus DM, Minus DM]

func RemoveFromArr added in v0.1.3

func RemoveFromArr[T comparable](arr []T, it T, num int) []T

func StdDevBy

func StdDevBy(obj *Series, period int, ddof int) (*Series, *Series)
StdDevBy Standard Deviation

suggest period: 20

return [stddev,sumVal]

func StochRSI added in v0.1.3

func StochRSI(obj *Series, rsiLen int, stochLen int, maK int, maD int) (*Series, *Series)

StochRSI StochasticRSI

rsiLen: 14, stochLen: 14, maK: 3, maD: 3

return [fastK, fastD]

func WrapFloatArr added in v0.2.1

func WrapFloatArr(res *Series, period int, inVal float64) []float64

Types

type BarEnv

type BarEnv struct {
	TimeStart  int64
	TimeStop   int64
	Exchange   string
	MarketType string
	Symbol     string
	TimeFrame  string
	TFMSecs    int64 //周期的毫秒间隔
	BarNum     int
	MaxCache   int
	VNum       int
	Open       *Series
	High       *Series
	Low        *Series
	Close      *Series
	Volume     *Series
	Info       *Series
	Data       sync.Map // map[string]interface{}
	Items      map[int]*Series
	Lock       sync.Mutex // 用户手动控制的锁,用于保护并发访问
}

func NewBarEnv added in v0.3.5

func NewBarEnv(exgName, market, symbol, timeframe string) (*BarEnv, error)

func (*BarEnv) BarCount added in v0.1.8

func (e *BarEnv) BarCount(start int64) float64

func (*BarEnv) Clone added in v0.3.4

func (e *BarEnv) Clone() *BarEnv

func (*BarEnv) NewSeries added in v0.1.3

func (e *BarEnv) NewSeries(data []float64) *Series

func (*BarEnv) OnBar

func (e *BarEnv) OnBar(barMs int64, open, high, low, close, volume, info float64) error

func (*BarEnv) OnBar2 added in v0.3.4

func (e *BarEnv) OnBar2(barMS, endMS int64, open, high, low, close, volume, info float64)

func (*BarEnv) Reset

func (e *BarEnv) Reset()

func (*BarEnv) ResetTo added in v0.3.4

func (e *BarEnv) ResetTo(env *BarEnv)

ResetTo reset all Series to given(exclude ohlcv)

func (*BarEnv) TrimOverflow

func (e *BarEnv) TrimOverflow()

type CCentre added in v0.1.3

type CCentre struct {
	*CTwoPoint
	Overlap [2]float64 // 中枢重叠区间
	Range   [2]float64 // 中枢高低区间
	Dirt    float64
}

中枢

func (*CCentre) SetEnd added in v0.1.3

func (c *CCentre) SetEnd(p *CPoint)

type CGraph added in v0.1.3

type CGraph struct {
	Pens       []*CPen
	Segs       []*CSeg
	Trends     []*CTrend
	Bars       []*Kline
	Centres    []*CCentre
	OnPoint    func(p *CPoint, evt int)
	OnPen      func(p *CPen, evt int)
	OnSeg      func(p *CSeg, evt int)
	OnCentre   func(c *CCentre, evt int)
	BarNum     int // 最后一个bar的序号,从1开始
	ParseLevel int // 期望解析到的等级,0不限制
	ParseTo    int // 解析到K线的位置,序号,非索引
	MaxPen     int // 保存最大笔数量,默认1000
	// contains filtered or unexported fields
}

func (*CGraph) AddBar added in v0.1.3

func (c *CGraph) AddBar(e *BarEnv) *CGraph

func (*CGraph) AddBars added in v0.1.3

func (c *CGraph) AddBars(barId int, bars ...*Kline) *CGraph

func (*CGraph) AddPen added in v0.1.3

func (c *CGraph) AddPen(pen *CPen)

AddPen 添加到Pens

func (*CGraph) AddSeg added in v0.1.3

func (c *CGraph) AddSeg(seg *CSeg)

func (*CGraph) Bar added in v0.1.3

func (c *CGraph) Bar(v int) *Kline

Bar 返回指定序号的Bar

func (*CGraph) Dump added in v0.1.3

func (c *CGraph) Dump() []*DrawLine

func (*CGraph) NewPen added in v0.1.3

func (c *CGraph) NewPen(a, b *CPoint) *CPen

func (*CGraph) NewPoint added in v0.1.3

func (c *CGraph) NewPoint(dirt float64, price float64, barId int) *CPoint

NewPoint 返回新点,不添加到Points

func (*CGraph) Parse added in v0.1.3

func (c *CGraph) Parse()

func (*CGraph) Remove added in v0.1.3

func (c *CGraph) Remove(o interface{}) bool

type CPen added in v0.1.3

type CPen struct {
	*CTwoPoint
	Dirt float64 // 1向上   -1向下
	Prev *CPen
	Next *CPen
}

func (*CPen) Clear added in v0.1.3

func (p *CPen) Clear()

Clear 删除笔对前后的关联

func (*CPen) Clone added in v0.1.3

func (p *CPen) Clone() *CPen

type CPoint added in v0.1.3

type CPoint struct {
	Graph      *CGraph
	Dirt       float64 // 1顶分型,-1底分型
	BarId      int     // 此bar的序号
	Price      float64 // 价格
	StartPen   *CPen
	EndPen     *CPen
	StartSeg   *CSeg
	EndSeg     *CSeg
	StartTrend *CTrend
	EndTrend   *CTrend
	Next       *CPoint
}

func (*CPoint) Clear added in v0.1.3

func (p *CPoint) Clear()

func (*CPoint) Clone added in v0.1.3

func (p *CPoint) Clone() *CPoint

func (*CPoint) Move added in v0.1.3

func (p *CPoint) Move(barId int, price float64) *CPoint

func (*CPoint) PenTo added in v0.1.3

func (p *CPoint) PenTo(other *CPoint) *CPen

func (*CPoint) PensTo added in v0.1.3

func (p *CPoint) PensTo(end *CPoint) []*CPen

PensTo 从当前点出发,到指定点的所有笔

func (*CPoint) State added in v0.1.3

func (p *CPoint) State() int

State 分型状态,只返回CLInit/CLDone分别表示无效、有效

func (*CPoint) StrPoint added in v0.1.3

func (p *CPoint) StrPoint() string

type CSeg added in v0.1.3

type CSeg struct {
	*CTwoPoint
	Dirt    float64      // 1向上  0不确定  -1向下
	Feas    [][2]float64 // 特征序列
	InForce bool         // 标记此线段是否必须以顶底分型确认
	Temp    bool         // 标记此线段是假设的,需要再次检查是否有效
	Prev    *CSeg
	Next    *CSeg
	Centre  *CCentre // 此线段所属中枢,只对中间部分线段设置;一个线段只可属于一个中枢
}

线段

func (*CSeg) AddFeature added in v0.1.3

func (s *CSeg) AddFeature(f [2]float64)

AddFeature 将笔作为特征序列

func (*CSeg) CalcFeatures added in v0.1.3

func (s *CSeg) CalcFeatures()

CalcFeatures 重新计算线段的所有特征序列,当线段结束点修改时调用此方法

func (*CSeg) Clear added in v0.1.3

func (s *CSeg) Clear()

func (*CSeg) IsValid added in v0.1.3

func (s *CSeg) IsValid() bool

func (*CSeg) SetEnd added in v0.1.3

func (s *CSeg) SetEnd(p *CPoint)

func (*CSeg) SetLastFea added in v0.1.3

func (s *CSeg) SetLastFea(f [2]float64)

type CTrend added in v0.1.3

type CTrend struct {
	*CTwoPoint
	Dirt float64 // 1向上  0不确定  -1向下
	Prev *CTrend
	Next *CTrend
}

func (*CTrend) Clear added in v0.1.3

func (t *CTrend) Clear()

type CTwoPoint added in v0.1.3

type CTwoPoint struct {
	Graph *CGraph
	Start *CPoint
	End   *CPoint
	State int // 状态:0/1/2
}

func (*CTwoPoint) String added in v0.1.3

func (p *CTwoPoint) String() string

func (*CTwoPoint) ToFeature added in v0.1.3

func (p *CTwoPoint) ToFeature() [2]float64

type CrossLog

type CrossLog struct {
	Time    int64
	PrevVal float64
	Hist    []*XState // 正数表示上穿,负数下穿,绝对值表示BarNum
}

func (*CrossLog) Clone added in v0.3.4

func (c *CrossLog) Clone() *CrossLog

type DrawLine added in v0.1.3

type DrawLine struct {
	StartPos   int
	StartPrice float64
	StopPos    int
	StopPrice  float64
}

type Kline

type Kline struct {
	Time   int64
	Open   float64
	High   float64
	Low    float64
	Close  float64
	Volume float64
	Info   float64
}

type Series

type Series struct {
	ID      int
	Env     *BarEnv
	Data    []float64
	Cols    []*Series
	Time    int64
	More    interface{}
	DupMore func(interface{}) interface{}
	Subs    map[string]map[int]*Series // 由此序列派生的;function:hash:object
	XLogs   map[int]*CrossLog          // 此序列交叉记录
}

func ADL added in v0.1.3

func ADL(env *BarEnv) *Series

ADL Accumulation/Distribution Line

func ADX

func ADX(high *Series, low *Series, close *Series, period int) *Series

ADX Average Directional Index

suggest period: 14

return maDX

func ADXBy added in v0.1.3

func ADXBy(high *Series, low *Series, close *Series, period, smoothing, method int) *Series
ADXBy Average Directional Index

method=0 classic ADX method=1 TradingView "ADX and DI for v4"

suggest period: 14 smoothing: 0 to use period

return maDX

func ALMA added in v0.1.6

func ALMA(obj *Series, period int, sigma, distOff float64) *Series

ALMA Arnaud Legoux Moving Average

period: window size. Default: 10

sigma: Smoothing value. Default 6.0

distOff: min 0 (smoother), max 1 (more responsive). Default: 0.85

func ATR

func ATR(high *Series, low *Series, close *Series, period int) *Series

ATR Average True Range

suggest period: 14

func AvgDev added in v0.1.3

func AvgDev(obj *Series, period int) *Series

AvgDev sum(abs(Vi - mean))/period

func AvgPrice added in v0.1.3

func AvgPrice(e *BarEnv) *Series

AvgPrice typical price=(h+l+c)/3

func CCI added in v0.1.3

func CCI(obj *Series, period int) *Series
CCI Commodity Channel Index

https://www.tradingview.com/support/solutions/43000502001-commodity-channel-index-cci/

suggest period: 20

func CHOP added in v0.1.6

func CHOP(e *BarEnv, period int) *Series

CHOP Choppiness Index

suggest period: 14

higher values equal more choppiness, while lower values indicate directional trending. 值越高,波动性越大,而值越低,则表示有方向性趋势。

func CMF added in v0.1.3

func CMF(env *BarEnv, period int) *Series

CMF Chaikin Money Flow

https://www.tradingview.com/scripts/chaikinmoneyflow/?solution=43000501974

suggest period: 20

func CMO added in v0.1.6

func CMO(obj *Series, period int) *Series

CMO Chande Momentum Oscillator

suggest period: 9

Same implementation as ta-lib For TradingView, use: CMOBy(obj, period, 1)

func CMOBy added in v0.1.6

func CMOBy(obj *Series, period int, maType int) *Series

CMOBy Chande Momentum Oscillator

suggest period: 9

maType: 0: ta-lib 1: tradingView

func CRSI added in v0.1.8

func CRSI(obj *Series, period, upDn, roc int) *Series

CRSI Connors RSI

suggest period:3, upDn:2, roc:100

Basically the same as TradingView

func CRSIBy added in v0.1.8

func CRSIBy(obj *Series, period, upDn, roc, vtype int) *Series

CRSIBy Connors RSI

suggest period:3, upDn:2, roc:100

vtype: 0 Calculation in TradingView method

1 Calculation in ta-lib community method:

chg = close_col / close_col.shift(1)
updown = np.where(chg.gt(1), 1.0, np.where(chg.lt(1), -1.0, 0.0))
rsi = ta.RSI(close_arr, timeperiod=3)
ud = ta.RSI(updown, timeperiod=2)
roc = ta.ROC(close_arr, 100)
crsi = (rsi + ud + roc) / 3

func CTI added in v0.1.4

func CTI(obj *Series, period int) *Series

CTI Correlation Trend Indicator

The Correlation Trend Indicator is an oscillator created by John Ehler in 2020. It assigns a value depending on how close prices in that range are to following a positively- or negatively-sloping straight line. Values range from -1 to 1. This is a wrapper for LinRegAdv.

suggest period: 20

func ChaikinOsc added in v0.1.3

func ChaikinOsc(env *BarEnv, shortLen int, longLen int) *Series

ChaikinOsc Chaikin Oscillator

https://www.tradingview.com/support/solutions/43000501979-chaikin-oscillator/

short: 3, long: 10

func DV2 added in v0.1.10

func DV2(h, l, c *Series, period, maLen int) *Series

DV2 Developed by David Varadi of http://cssanalytics.wordpress.com/

period: 252   maLen: 2

This seems to be the *Bounded* version.
这里和backtrader中实现不一致,是另一个版本。

See also:

  - http://web.archive.org/web/20131216100741/http://quantingdutchman.wordpress.com/2010/08/06/dv2-indicator-for-amibroker/
  - https://www.reddit.com/r/CapitalistExploits/comments/1d0azms/david_varadis_dv2_indicator_trading_strategies/

func EMA

func EMA(obj *Series, period int) *Series

EMA Exponential Moving Average 指数移动均线

Latest value weight: 2/(n+1)

最近一个权重:2/(n+1)

func EMABy

func EMABy(obj *Series, period int, initType int) *Series

EMABy 指数移动均线 最近一个权重:2/(n+1) initType:0使用SMA初始化,1第一个有效值初始化

func ER added in v0.1.5

func ER(obj *Series, period int) *Series

ER Efficiency Ratio / Trend to Noise Ratio

suggest period: 8

func HL2 added in v0.1.6

func HL2(h, l *Series) *Series

func HLC3 added in v0.1.8

func HLC3(h, l, c *Series) *Series

HLC3 typical price=(h+l+c)/3

func HMA added in v0.1.4

func HMA(obj *Series, period int) *Series

HMA Hull Moving Average

suggest period: 9

func Highest

func Highest(obj *Series, period int) *Series

func HighestBar added in v0.1.3

func HighestBar(obj *Series, period int) *Series

func KAMA added in v0.1.3

func KAMA(obj *Series, period int) *Series

KAMA Kaufman Adaptive Moving Average

period: 10 fixed: (fast: 2, slow: 30)

func KAMABy added in v0.1.3

func KAMABy(obj *Series, period int, fast, slow int) *Series

KAMABy Kaufman Adaptive Moving Average

period: 10, fast: 2, slow: 30

func LinReg added in v0.1.4

func LinReg(obj *Series, period int) *Series

LinReg Linear Regression Moving Average

Linear Regression Moving Average (LINREG). This is a simplified version of a Standard Linear Regression. LINREG is a rolling regression of one variable. A Standard Linear Regression is between two or more variables.

func LinRegAdv added in v0.1.4

func LinRegAdv(obj *Series, period int, angle, intercept, degrees, r, slope, tsf bool) *Series

func Lowest

func Lowest(obj *Series, period int) *Series

func LowestBar added in v0.1.3

func LowestBar(obj *Series, period int) *Series

func MFI added in v0.1.3

func MFI(e *BarEnv, period int) *Series

MFI Money Flow Index

https://corporatefinanceinstitute.com/resources/career-map/sell-side/capital-markets/money-flow-index/

suggest period: 14

func PercentRank added in v0.1.8

func PercentRank(obj *Series, period int) *Series

PercentRank

calculates the percentile rank of a bar value in a data set.

func RMA

func RMA(obj *Series, period int) *Series

RMA Relative Moving Average 相对移动均线

The difference from EMA is: both the numerator and denominator are reduced by 1 Latest value weight: 1/n

和EMA区别是:分子分母都减一
最近一个权重:1/n

func RMABy

func RMABy(obj *Series, period int, initType int, initVal float64) *Series

RMABy Relative Moving Average 相对移动均线

The difference from EMA is: both the numerator and denominator are reduced by 1 The most recent weight: 1/n

和EMA区别是:分子分母都减一
最近一个权重:1/n

initType: 0 initialize with SMA, 1 initialize with the first valid value

initVal defaults to Nan

initType:0使用SMA初始化,1第一个有效值初始化

initVal 默认Nan

func RMI added in v0.1.3

func RMI(obj *Series, period int, montLen int) *Series

RMI Relative Momentum Index https://theforexgeek.com/relative-momentum-index/

period: 14, montLen: 3

func ROC

func ROC(obj *Series, period int) *Series

ROC rate of change

suggest period: 9

func RSI

func RSI(obj *Series, period int) *Series

RSI Relative Strength Index 计算相对强度指数

suggest period: 14

func RSI50 added in v0.1.3

func RSI50(obj *Series, period int) *Series

RSI50 Relative Strength Index 计算相对强度指数-50

func SMA

func SMA(obj *Series, period int) *Series

func STC added in v0.1.11

func STC(obj *Series, period, fast, slow int, alpha float64) *Series

STC colored indicator

period: 12 fast: 26 slow: 50 alpha: 0.5

https://www.tradingview.com/u/shayankm/

func StdDev

func StdDev(obj *Series, period int) *Series
StdDev Standard Deviation 标准差

suggest period: 20

func Stiffness added in v0.1.6

func Stiffness(obj *Series, maLen, stiffLen, stiffMa int) *Series

Stiffness Indicator

maLen: 100, stiffLen: 60, stiffMa: 3

func Stoch added in v0.1.3

func Stoch(high, low, close *Series, period int) *Series

Stoch 100 * (close - lowest(low, period)) / (highest(high, period) - lowest(low, period))

use KDJ if you want to apply SMA/RMA to this

suggest period: 14

func Sum

func Sum(obj *Series, period int) *Series

func TD

func TD(obj *Series) *Series
TD Tom DeMark Sequence(狄马克序列)

over bought: 9,13

over sell: -9, -13

9和13表示超买;-9和-13表示超卖

func TR

func TR(high *Series, low *Series, close *Series) *Series

func UTBot added in v0.1.11

func UTBot(c, atr *Series, rate float64) *Series

UTBot UT Bot Alerts from TradingView

func UpDown added in v0.1.8

func UpDown(obj *Series, vtype int) *Series

UpDown

vtype: 0 TradingView (Count consecutive times)

1 classic (abs count up to 1)

func VWMA added in v0.1.3

func VWMA(price *Series, vol *Series, period int) *Series

VWMA Volume Weighted Moving Average 成交量加权平均价格

sum(price*volume)/sum(volume)

suggest period: 20

func WMA added in v0.1.4

func WMA(obj *Series, period int) *Series

WMA Weighted Moving Average.

the weighting factors decrease in arithmetic progression.

suggest period: 9

func WillR added in v0.1.3

func WillR(e *BarEnv, period int) *Series

WillR William's Percent R

suggest period: 14

func (*Series) Abs

func (s *Series) Abs() *Series

func (*Series) Add

func (s *Series) Add(obj interface{}) *Series

func (*Series) Append

func (s *Series) Append(obj interface{}) *Series

func (*Series) Back added in v0.1.3

func (s *Series) Back(num int) *Series

func (*Series) Cached

func (s *Series) Cached() bool

func (*Series) CopyTo added in v0.3.4

func (s *Series) CopyTo(e *BarEnv) *Series

func (*Series) Cross added in v0.3.1

func (s *Series) Cross(obj2 interface{}) int

Cross 计算最近一次交叉的距离。比较对象必须是常数或Series对象 返回值:正数上穿,负数下穿,0表示未知或重合;abs(ret) - 1表示交叉点与当前bar的距离

func (*Series) Cut

func (s *Series) Cut(keepNum int)

func (*Series) Div added in v0.3.0

func (s *Series) Div(obj interface{}) *Series

func (*Series) Get

func (s *Series) Get(i int) float64

func (*Series) Len

func (s *Series) Len() int

func (*Series) Max added in v0.1.8

func (s *Series) Max(obj interface{}) *Series

func (*Series) Min added in v0.1.8

func (s *Series) Min(obj interface{}) *Series

func (*Series) Mul

func (s *Series) Mul(obj interface{}) *Series

func (*Series) Range

func (s *Series) Range(start, stop int) []float64

Range 获取范围内的值。 start 起始位置,0是最近的 stop 结束位置,不含

func (*Series) RangeValid added in v0.3.0

func (s *Series) RangeValid(start, stop int) ([]float64, []int)

RangeValid 获取范围内的值,跳过nan。 start 起始位置,0是最近的 stop 结束位置,不含

func (*Series) Set added in v0.1.3

func (s *Series) Set(obj interface{}) *Series

func (*Series) Sub

func (s *Series) Sub(obj interface{}) *Series

func (*Series) To added in v0.1.3

func (s *Series) To(k string, v int) *Series

type XState

type XState struct {
	Sign   int
	BarNum int
}

func (*XState) Clone added in v0.3.4

func (s *XState) Clone() *XState

Directories

Path Synopsis
python
ta
tav
Package tav provides a gopy-compatible wrapper for the github.com/banbox/banta/tav library.
Package tav provides a gopy-compatible wrapper for the github.com/banbox/banta/tav library.

Jump to

Keyboard shortcuts

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