bbgo_origin/pkg/indicator/v2/atrp.go

24 lines
453 B
Go
Raw Normal View History

2023-07-10 08:54:22 +00:00
package indicatorv2
import "github.com/c9s/bbgo/pkg/types"
2023-06-02 10:56:28 +00:00
type ATRPStream struct {
2023-07-10 08:54:22 +00:00
*types.Float64Series
2023-06-02 10:56:28 +00:00
}
func ATRP2(source KLineSubscription, window int) *ATRPStream {
s := &ATRPStream{
2023-07-10 08:54:22 +00:00
Float64Series: types.NewFloat64Series(),
}
2023-06-02 10:56:28 +00:00
tr := TR2(source)
atr := RMA2(tr, window, true)
atr.OnUpdate(func(x float64) {
// x is the last rma
k := source.Last(0)
cloze := k.Close.Float64()
atrp := x / cloze
s.PushAndEmit(atrp)
})
return s
}