From 35b15c35e60b7657b968fe155b33a3fb018be344 Mon Sep 17 00:00:00 2001 From: c9s Date: Sun, 18 Feb 2024 23:41:24 +0800 Subject: [PATCH] doc: add one more example to chain the indicators together --- doc/development/indicator.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/doc/development/indicator.md b/doc/development/indicator.md index 08cb1430c..962e8c909 100644 --- a/doc/development/indicator.md +++ b/doc/development/indicator.md @@ -50,12 +50,32 @@ To create an EMA indicator instance, again, simply pass the closePrice indicator ema := indicatorv2.EMA(closePrices, 17) ``` -If you want to listen to the EMA value events, just add a callback on the indicator instance: +If you want to listen to the EMA value events, add a callback on the indicator instance: ```go ema.OnUpdate(func(v float64) { .... }) ``` + +To combine these techniques together: + +```go + +// use dot import to use the constructors as helpers +import . "github.com/c9s/bbgo/pkg/indicator/v2" + +func main() { + // you should get the correct stream instance from the *bbgo.ExchangeSession instance + stream := &types.Stream{} + + ema := EMA( + ClosePrices( + KLines(stream, types.Interval1m)), 14) + _ = ema +} +``` + + ## Adding New Indicator Adding a new indicator is pretty straightforward. Simply create a new struct and insert the necessary parameters as