mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
indicator: check valid window value for RMA
This commit is contained in:
parent
2d578db12f
commit
bc7f2687f8
|
@ -20,6 +20,8 @@ type RMAStream struct {
|
|||
}
|
||||
|
||||
func RMA2(source types.Float64Source, window int, adjust bool) *RMAStream {
|
||||
checkWindow(window)
|
||||
|
||||
s := &RMAStream{
|
||||
Float64Series: types.NewFloat64Series(),
|
||||
window: window,
|
||||
|
@ -53,7 +55,6 @@ func (s *RMAStream) Calculate(x float64) float64 {
|
|||
|
||||
s.Slice.Push(tmp)
|
||||
s.previous = tmp
|
||||
|
||||
return tmp
|
||||
}
|
||||
|
||||
|
@ -62,3 +63,9 @@ func (s *RMAStream) Truncate() {
|
|||
s.Slice = s.Slice[MaxNumOfRMATruncateSize-1:]
|
||||
}
|
||||
}
|
||||
|
||||
func checkWindow(window int) {
|
||||
if window == 0 {
|
||||
panic("window can not be zero")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user