mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
doc: update indicator doc
This commit is contained in:
parent
e6c634690b
commit
3f800243a7
|
@ -69,23 +69,43 @@ try to create new indicators in `pkg/indicator/` folder, and add compilation hin
|
||||||
// go:generate callbackgen -type StructName
|
// go:generate callbackgen -type StructName
|
||||||
type StructName struct {
|
type StructName struct {
|
||||||
...
|
...
|
||||||
UpdateCallbacks []func(value float64)
|
updateCallbacks []func(value float64)
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
And implement required interface methods:
|
And implement required interface methods:
|
||||||
```go
|
```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
|
// custom function
|
||||||
func (inc *StructName) calculateAndUpdate(kLines []types.KLine) {
|
func (inc *StructName) CalculateAndUpdate(kLines []types.KLine) {
|
||||||
// calculation...
|
if len(inc.Values) == 0 {
|
||||||
// assign the result to calculatedValue
|
// 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
|
inc.EmitUpdate(calculatedValue) // produce data, broadcast to the subscribers
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// custom function
|
// custom function
|
||||||
func (inc *StructName) handleKLineWindowUpdate(interval types.Interval, window types.KLineWindow) {
|
func (inc *StructName) handleKLineWindowUpdate(interval types.Interval, window types.KLineWindow) {
|
||||||
// filter on interval
|
// filter on interval
|
||||||
inc.calculateAndUpdate(window)
|
inc.CalculateAndUpdate(window)
|
||||||
}
|
}
|
||||||
|
|
||||||
// required
|
// required
|
||||||
|
|
Loading…
Reference in New Issue
Block a user