mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +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 {
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user