indicator: check valid window value for RMA

This commit is contained in:
c9s 2023-09-26 20:42:18 +08:00
parent 2d578db12f
commit bc7f2687f8
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -20,6 +20,8 @@ type RMAStream struct {
} }
func RMA2(source types.Float64Source, window int, adjust bool) *RMAStream { func RMA2(source types.Float64Source, window int, adjust bool) *RMAStream {
checkWindow(window)
s := &RMAStream{ s := &RMAStream{
Float64Series: types.NewFloat64Series(), Float64Series: types.NewFloat64Series(),
window: window, window: window,
@ -53,7 +55,6 @@ func (s *RMAStream) Calculate(x float64) float64 {
s.Slice.Push(tmp) s.Slice.Push(tmp)
s.previous = tmp s.previous = tmp
return tmp return tmp
} }
@ -62,3 +63,9 @@ func (s *RMAStream) Truncate() {
s.Slice = s.Slice[MaxNumOfRMATruncateSize-1:] s.Slice = s.Slice[MaxNumOfRMATruncateSize-1:]
} }
} }
func checkWindow(window int) {
if window == 0 {
panic("window can not be zero")
}
}