Documentation ¶
Index ¶
- Constants
- Variables
- func Cross(se *Series, obj2 interface{}) int
- func RemoveFromArr[T comparable](arr []T, it T, num int) []T
- type BarEnv
- type CCentre
- type CGraph
- func (c *CGraph) AddBar(e *BarEnv) *CGraph
- func (c *CGraph) AddBars(barId int, bars ...*Kline) *CGraph
- func (c *CGraph) AddPen(pen *CPen)
- func (c *CGraph) AddSeg(seg *CSeg)
- func (c *CGraph) Bar(v int) *Kline
- func (c *CGraph) Dump() []*DrawLine
- func (c *CGraph) NewPen(a, b *CPoint) *CPen
- func (c *CGraph) NewPoint(dirt float64, price float64, barId int) *CPoint
- func (c *CGraph) Parse()
- func (c *CGraph) Remove(o interface{}) bool
- type CPen
- type CPoint
- type CSeg
- type CTrend
- type CTwoPoint
- type CrossLog
- type DrawLine
- type Kline
- type Series
- func ADL(env *BarEnv) *Series
- func ADX(high *Series, low *Series, close *Series, period int) *Series
- func ADXBy(high *Series, low *Series, close *Series, period int, method int) *Series
- func ALMA(obj *Series, period int, sigma, distOff float64) *Series
- func ATR(high *Series, low *Series, close *Series, period int) *Series
- func Aroon(high *Series, low *Series, period int) *Series
- func AvgDev(obj *Series, period int) *Series
- func AvgPrice(e *BarEnv) *Series
- func BBANDS(obj *Series, period int, stdUp, stdDn float64) *Series
- func CCI(obj *Series, period int) *Series
- func CHOP(e *BarEnv, period int) *Series
- func CMF(env *BarEnv, period int) *Series
- func CMO(obj *Series, period int) *Series
- func CMOBy(obj *Series, period int, maType int) *Series
- func CRSI(obj *Series, period, upDn, roc int) *Series
- func CRSIBy(obj *Series, period, upDn, roc, vtype int) *Series
- func CTI(obj *Series, period int) *Series
- func ChaikinOsc(env *BarEnv, short int, long int) *Series
- func EMA(obj *Series, period int) *Series
- func EMABy(obj *Series, period int, initType int) *Series
- func ER(obj *Series, period int) *Series
- func HL2(h, l *Series) *Series
- func HLC3(h, l, c *Series) *Series
- func HMA(obj *Series, period int) *Series
- func HeikinAshi(e *BarEnv) *Series
- func Highest(obj *Series, period int) *Series
- func HighestBar(obj *Series, period int) *Series
- func KAMA(obj *Series, period int) *Series
- func KAMABy(obj *Series, period int, fast, slow int) *Series
- func KDJ(high *Series, low *Series, close *Series, period int, sm1 int, sm2 int) *Series
- func KDJBy(high *Series, low *Series, close *Series, period int, sm1 int, sm2 int, ...) *Series
- func LinReg(obj *Series, period int) *Series
- func LinRegAdv(obj *Series, period int, angle, intercept, degrees, r, slope, tsf bool) *Series
- func Lowest(obj *Series, period int) *Series
- func LowestBar(obj *Series, period int) *Series
- func MACD(obj *Series, fast int, slow int, smooth int) *Series
- func MACDBy(obj *Series, fast int, slow int, smooth int, initType int) *Series
- func MFI(e *BarEnv, period int) *Series
- func PercentRank(obj *Series, period int) *Series
- func PluMinDI(high *Series, low *Series, close *Series, period int) *Series
- func PluMinDM(high *Series, low *Series, close *Series, period int) *Series
- func RMA(obj *Series, period int) *Series
- func RMABy(obj *Series, period int, initType int, initVal float64) *Series
- func RMI(obj *Series, period int, montLen int) *Series
- func ROC(obj *Series, period int) *Series
- func RSI(obj *Series, period int) *Series
- func RSI50(obj *Series, period int) *Series
- func SMA(obj *Series, period int) *Series
- func StdDev(obj *Series, period int) *Series
- func StdDevBy(obj *Series, period int, ddof int) *Series
- func Stiffness(obj *Series, maLen, stiffLen, stiffMa int) *Series
- func Stoch(high, low, close *Series, period int) *Series
- func StochRSI(obj *Series, rsiLen int, stochLen int, maK int, maD int) *Series
- func Sum(obj *Series, period int) *Series
- func TD(obj *Series) *Series
- func TR(high *Series, low *Series, close *Series) *Series
- func UpDown(obj *Series, vtype int) *Series
- func VWMA(price *Series, vol *Series, period int) *Series
- func WMA(obj *Series, period int) *Series
- func WillR(e *BarEnv, period int) *Series
- func (s *Series) Abs() *Series
- func (s *Series) Add(obj interface{}) *Series
- func (s *Series) Append(obj interface{}) *Series
- func (s *Series) Back(num int) *Series
- func (s *Series) Cached() bool
- func (s *Series) Cut(keepNum int)
- func (s *Series) Get(i int) float64
- func (s *Series) Len() int
- func (s *Series) Max(obj interface{}) *Series
- func (s *Series) Min(obj interface{}) *Series
- func (s *Series) Mul(obj interface{}) *Series
- func (s *Series) Range(start, stop int) []float64
- func (s *Series) Set(obj interface{}) *Series
- func (s *Series) Sub(obj interface{}) *Series
- func (s *Series) To(k string, v int) *Series
- type XState
Constants ¶
const ( MinPenLen = 5 CLInit = 0 // 尚未确认有效 CLValid = 1 // 确认有效,尚未完成 CLDone = 2 // 确认有效,已完成,不会再改 ParseLevelPen = 1 ParseLevelSeg = 2 ParseLevelCentre = 3 ParseLevelTrend = 4 DefMaxPen = 1000 // 默认保存的最大笔数量 )
const ( EvtNew = 1 EvtChange = 2 EvtRemove = 3 )
Variables ¶
var ( ErrInvalidSeriesVal = errors.New("invalid val for Series") ErrGetDataOfMerged = errors.New("try get Data of merged series var") )
Functions ¶
func Cross ¶
Cross 计算最近一次交叉的距离。如果两个都变化,则两个都必须是序列。或者一个是常数一个是序列 返回值:正数上穿,负数下穿,0表示未知或重合;abs(ret) - 1表示交叉点与当前bar的距离
func RemoveFromArr ¶ added in v0.1.3
func RemoveFromArr[T comparable](arr []T, it T, num int) []T
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 map[string]interface{} }
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 }
中枢
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 }
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 }
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
AddFeature 将笔作为特征序列
func (*CSeg) CalcFeatures ¶ added in v0.1.3
func (s *CSeg) CalcFeatures()
CalcFeatures 重新计算线段的所有特征序列,当线段结束点修改时调用此方法
func (*CSeg) SetLastFea ¶ added in v0.1.3
type Series ¶
type Series struct { ID int Env *BarEnv Data []float64 Cols []*Series Time int64 More interface{} Subs map[string]map[int]*Series // 由此序列派生的;function:hash:object XLogs map[int]*CrossLog // 此序列交叉记录 // contains filtered or unexported fields }
func ADXBy ¶ added in v0.1.3
ADXBy Average Directional Index
method=0 classic ADX method=1 TradingView "ADX and DI for v4"
suggest period: 14
return [maDX, plusDI, minusDI]
func ALMA ¶ added in v0.1.6
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 Aroon ¶ added in v0.1.3
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 ¶
BBANDS Bollinger Bands 布林带指标
period: 20, stdUp: 2, stdDn: 2
return [upper, mid, lower]
func CCI ¶ added in v0.1.3
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
CHOP Choppiness Index
suggest period: 14
higher values equal more choppiness, while lower values indicate directional trending. 值越高,波动性越大,而值越低,则表示有方向性趋势。
func CMF ¶ added in v0.1.3
CMF Chaikin Money Flow
https://www.tradingview.com/scripts/chaikinmoneyflow/?solution=43000501974
suggest period: 20
func CMO ¶ added in v0.1.6
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
CMOBy Chande Momentum Oscillator
suggest period: 9
maType: 0: ta-lib 1: tradingView
func CRSI ¶ added in v0.1.8
CRSI Connors RSI
suggest period:3, upDn:2, roc:100
Basically the same as TradingView
func CRSIBy ¶ added in v0.1.8
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
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
ChaikinOsc Chaikin Oscillator
https://www.tradingview.com/support/solutions/43000501979-chaikin-oscillator/
short: 3, long: 10
func HighestBar ¶ added in v0.1.3
func KAMA ¶ added in v0.1.3
KAMA Kaufman Adaptive Moving Average
period: 10 fixed: (fast: 2, slow: 30)
func KDJBy ¶
func KDJBy(high *Series, low *Series, close *Series, period int, sm1 int, sm2 int, maBy string) *Series
KDJBy alias: stoch indicator;
period: 9, sm1: 3, sm2: 3
return (K, D, RSV)
func LinReg ¶ added in v0.1.4
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 MACD ¶
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 PercentRank ¶ added in v0.1.8
PercentRank
calculates the percentile rank of a bar value in a data set.
func RMA ¶
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 ¶
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
RMI Relative Momentum Index https://theforexgeek.com/relative-momentum-index/
period: 14, montLen: 3
func Stoch ¶ added in v0.1.3
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 StochRSI ¶ added in v0.1.3
StochRSI StochasticRSI
rsiLen: 14, stochLen: 14, maK: 3, maD: 3
return [fastK, fastD]
func UpDown ¶ added in v0.1.8
UpDown
vtype: 0 TradingView (Count consecutive times)
1 classic (abs count up to 1)
func VWMA ¶ added in v0.1.3
VWMA Volume Weighted Moving Average 成交量加权平均价格
sum(price*volume)/sum(volume)
suggest period: 20
func WMA ¶ added in v0.1.4
WMA Weighted Moving Average.
the weighting factors decrease in arithmetic progression.
suggest period: 9