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.
36 lines
816 B
36 lines
816 B
package indicator |
|
|
|
import ( |
|
"sig-pub/pkg/types" |
|
|
|
"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) Meta() IndicatorMeta { |
|
return IndicatorMeta{ |
|
Name: "sma", |
|
Input: []types.InputArg{ |
|
{Name: "window", Type: types.InputTypeUInt, Desc: "窗口大小"}, |
|
}, |
|
} |
|
} |
|
|
|
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") |
|
closeSeries := ctx.Series(0, window).Close() |
|
sma := talib.Sma(closeSeries, int(window)) |
|
_ = sma[len(sma)-1] |
|
vector = closeSeries.Avg() |
|
return |
|
}
|
|
|