package indicator import ( "sig-pub/pkg/types" ) // RSI stateless indicator // 相对强弱指数 (RSI) rsi define: https://www.investopedia.com/terms/r/rsi.asp type SMA struct { } // indicator interface func (c *SMA) Meta() IndicatorMeta { return IndicatorMeta{ Name: "SMA", Input: []types.InputArg{ {Name: "window", Type: types.InputTypeUInt, Desc: "窗口大小", Default: 9}, {Name: "pt", Type: types.InputTypePriceType, Desc: "k线序列类型", Default: types.PriceTypeDefault}, }, } } func (c *SMA) CandlePeriods(ctx IIndicatorContext) int16 { return ctx.Input().Int16("window") } // Calculate 计算单根k线sma指标 func (c *SMA) Calculate(ctx IIndicatorContext) (vector float64) { window := ctx.Input().Int16("window") pt := ctx.Input().PriceType() priceSeries := ctx.Series(0, window).Price(pt) // sma := talib.Sma(closeSeries, int(window)) // _ = sma[len(sma)-1] vector = priceSeries.Avg() return }