mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
indicator: add ATRP indicator
This commit is contained in:
parent
8a8111140e
commit
aae7fd310e
19
pkg/indicator/v2_atrp.go
Normal file
19
pkg/indicator/v2_atrp.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
package indicator
|
||||
|
||||
type ATRPStream struct {
|
||||
Float64Series
|
||||
}
|
||||
|
||||
func ATRP2(source KLineSubscription, window int) *ATRPStream {
|
||||
s := &ATRPStream{}
|
||||
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
|
||||
}
|
|
@ -6,6 +6,8 @@ import (
|
|||
|
||||
type KLineSubscription interface {
|
||||
AddSubscriber(f func(k types.KLine))
|
||||
Length() int
|
||||
Last(i int) *types.KLine
|
||||
}
|
||||
|
||||
type PriceStream struct {
|
||||
|
|
Loading…
Reference in New Issue
Block a user