doc: add one more example to chain the indicators together

This commit is contained in:
c9s 2024-02-18 23:41:24 +08:00
parent 97cdf42643
commit 35b15c35e6
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -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