Documentation
¶
Index ¶
- Constants
- Variables
- func Aroon(high *Series, low *Series, period int) (*Series, *Series, *Series)
- func BBANDS(obj *Series, period int, stdUp, stdDn float64) (*Series, *Series, *Series)
- func Cross(obj1 *Series, obj2 interface{}) intdeprecated
- func HeikinAshi(e *BarEnv) (*Series, *Series, *Series, *Series)
- func KDJ(high *Series, low *Series, close *Series, period int, sm1 int, sm2 int) (*Series, *Series, *Series)
- func KDJBy(high *Series, low *Series, close *Series, period int, sm1 int, sm2 int, ...) (*Series, *Series, *Series)
- func MACD(obj *Series, fast int, slow int, smooth int) (*Series, *Series)
- func MACDBy(obj *Series, fast int, slow int, smooth int, initType int) (*Series, *Series)
- func ParseTimeFrame(timeframe string) (int, error)
- func PluMinDI(high *Series, low *Series, close *Series, period int) (*Series, *Series)
- func PluMinDM(high *Series, low *Series, close *Series, period int) (*Series, *Series)
- func RemoveFromArr[T comparable](arr []T, it T, num int) []T
- func StdDevBy(obj *Series, period int, ddof int) (*Series, *Series)
- func StochRSI(obj *Series, rsiLen int, stochLen int, maK int, maD int) (*Series, *Series)
- func WrapFloatArr(res *Series, period int, inVal float64) []float64
- type BarEnv
- func (e *BarEnv) BarCount(start int64) float64
- func (e *BarEnv) Clone() *BarEnv
- func (e *BarEnv) NewSeries(data []float64) *Series
- func (e *BarEnv) OnBar(barMs int64, open, high, low, close, volume, info float64) error
- func (e *BarEnv) OnBar2(barMS, endMS int64, open, high, low, close, volume, info float64)
- func (e *BarEnv) Reset()
- func (e *BarEnv) ResetTo(env *BarEnv)
- func (e *BarEnv) TrimOverflow()
- 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, smoothing, 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 AvgDev(obj *Series, period int) *Series
- func AvgPrice(e *BarEnv) *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, shortLen int, longLen int) *Series
- func DV2(h, l, c *Series, period, maLen 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 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 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 MFI(e *BarEnv, period int) *Series
- func PercentRank(obj *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 STC(obj *Series, period, fast, slow int, alpha float64) *Series
- func StdDev(obj *Series, period int) *Series
- func Stiffness(obj *Series, maLen, stiffLen, stiffMa int) *Series
- func Stoch(high, low, close *Series, period int) *Series
- func Sum(obj *Series, period int) *Series
- func TD(obj *Series) *Series
- func TR(high *Series, low *Series, close *Series) *Series
- func UTBot(c, atr *Series, rate float64) *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) CopyTo(e *BarEnv) *Series
- func (s *Series) Cross(obj2 interface{}) int
- func (s *Series) Cut(keepNum int)
- func (s *Series) Div(obj interface{}) *Series
- 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) RangeValid(start, stop int) ([]float64, []int)
- 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")
)
Functions ¶
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 HeikinAshi ¶
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 ¶
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 ParseTimeFrame ¶ added in v0.3.5
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 sync.Map // map[string]interface{}
Items map[int]*Series
Lock sync.Mutex // 用户手动控制的锁,用于保护并发访问
}
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{}
DupMore func(interface{}) interface{}
Subs map[string]map[int]*Series // 由此序列派生的;function:hash:object
XLogs map[int]*CrossLog // 此序列交叉记录
}
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 smoothing: 0 to use period
return maDX
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 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 DV2 ¶ added in v0.1.10
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 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 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 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 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
func (*Series) Cross ¶ added in v0.3.1
Cross 计算最近一次交叉的距离。比较对象必须是常数或Series对象 返回值:正数上穿,负数下穿,0表示未知或重合;abs(ret) - 1表示交叉点与当前bar的距离
func (*Series) RangeValid ¶ added in v0.3.0
RangeValid 获取范围内的值,跳过nan。 start 起始位置,0是最近的 stop 结束位置,不含