package indicator import ( "fmt" "sig-pub/pkg/types" "sig-pub/pkg/types/series" "github.com/spf13/cast" ) // RSI: 相对强弱指数 (RSI) // rsi define: https://www.investopedia.com/terms/r/rsi.asp type RSI struct { series.Series values series.Floats prices series.Floats baseline int32 } func NewRSI(baseline int32) *RSI { return &RSI{ baseline: baseline, } } func (ind *RSI) Init(prams map[string]any) { cast.ToIntE("1") } func (ind *RSI) Update(klines []types.Kline) (err error) { for _, kline := range klines { c, ok := kline.Close.Float64() if !ok { err = fmt.Errorf("kline close to float64 error: %s", kline.Close.String()) return } ind.prices.Push(c) } diff := ind.prices.Diff() _ = diff return }