doc: update indicator doc

This commit is contained in:
c9s 2022-07-14 09:34:48 +08:00
parent e6c634690b
commit 3f800243a7
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -69,23 +69,43 @@ try to create new indicators in `pkg/indicator/` folder, and add compilation hin
// go:generate callbackgen -type StructName
type StructName struct {
...
UpdateCallbacks []func(value float64)
updateCallbacks []func(value float64)
}
```
And implement required interface methods:
```go
func (inc *StructName) Update(value float64) {
// indicator calculation here...
// push value...
}
func (inc *StructName) PushK(k types.KLine) {
inc.Update(k.Close.Float64())
}
// custom function
func (inc *StructName) calculateAndUpdate(kLines []types.KLine) {
// calculation...
// assign the result to calculatedValue
func (inc *StructName) CalculateAndUpdate(kLines []types.KLine) {
if len(inc.Values) == 0 {
// preload or initialization
for _, k := range allKLines {
inc.PushK(k)
}
inc.EmitUpdate(inc.Last())
} else {
// update new value only
k := allKLines[len(allKLines)-1]
inc.PushK(k)
inc.EmitUpdate(calculatedValue) // produce data, broadcast to the subscribers
}
}
// custom function
func (inc *StructName) handleKLineWindowUpdate(interval types.Interval, window types.KLineWindow) {
// filter on interval
inc.calculateAndUpdate(window)
inc.CalculateAndUpdate(window)
}
// required