From aae7fd310ebed16e94992b0c7def97eb66e63b05 Mon Sep 17 00:00:00 2001 From: c9s Date: Fri, 2 Jun 2023 18:56:28 +0800 Subject: [PATCH] indicator: add ATRP indicator --- pkg/indicator/v2_atrp.go | 19 +++++++++++++++++++ pkg/indicator/v2_price.go | 2 ++ 2 files changed, 21 insertions(+) create mode 100644 pkg/indicator/v2_atrp.go diff --git a/pkg/indicator/v2_atrp.go b/pkg/indicator/v2_atrp.go new file mode 100644 index 000000000..6261c1cb3 --- /dev/null +++ b/pkg/indicator/v2_atrp.go @@ -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 +} diff --git a/pkg/indicator/v2_price.go b/pkg/indicator/v2_price.go index e80736715..d95976dda 100644 --- a/pkg/indicator/v2_price.go +++ b/pkg/indicator/v2_price.go @@ -6,6 +6,8 @@ import ( type KLineSubscription interface { AddSubscriber(f func(k types.KLine)) + Length() int + Last(i int) *types.KLine } type PriceStream struct {