You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

24 lines
535 B

package indicator
import (
"github.com/markcheno/go-talib"
)
// RSI stateless indicator
// 相对强弱指数 (RSI) rsi define: https://www.investopedia.com/terms/r/rsi.asp
type SMA struct {
}
// indicator interface
func (c *SMA) Name() string {
return "sma"
}
// Calculate 计算单根k线sma指标
func (c *SMA) Calculate(ctx IIndicatorContext, window int16) (vector float64) {
closeSeries := ctx.Series(0, window).Close()
sma := talib.Sma(closeSeries, int(window))
_ = sma[len(sma)-1]
vector = closeSeries.Avg()
return
}