From fcc0f184634fc687de3ddd397d3732cd6e0c98de Mon Sep 17 00:00:00 2001 From: zenix Date: Mon, 9 May 2022 10:55:32 +0900 Subject: [PATCH] doc: add more details on series.md. add link from indicator.md --- doc/development/indicator.md | 4 ++++ doc/development/series.md | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/doc/development/indicator.md b/doc/development/indicator.md index b6c1c72e2..dfab564ce 100644 --- a/doc/development/indicator.md +++ b/doc/development/indicator.md @@ -98,3 +98,7 @@ The `KLineWindowUpdater` interface is currently defined in `pkg/indicator/ewma.g Once the implementation is done, run `go generate` to generate the callback functions of the indicator. You should be able to implement your strategy and use the new indicator in the same way as `AD`. + +#### Generalize + +In order to provide indicator users a lower learning curve, we've designed the `types.Series` interface. We recommend indicator developers to also implement the `types.Series` interface to provide richer functionality on the computed result. To have deeper understanding how `types.Series` works, please refer to [doc/development/series.md](./series.md) diff --git a/doc/development/series.md b/doc/development/series.md index ce48019e4..08eec4711 100644 --- a/doc/development/series.md +++ b/doc/development/series.md @@ -5,7 +5,7 @@ In bbgo, we've added several interfaces to standardize the indicator protocol. The new interfaces will allow strategy developers switching similar indicators without checking the code. Signal contributors or indicator developers were also able to be benefit from the existing interface functions, such as `Add`, `Mul`, `Minus`, and `Div`, without rebuilding the wheels. -The series interface in bbgo borrows the concept of `series` type in pinescript that allow us to query data in time-based reverse order (data that created later will be the former object in series). Right now, based on the return type, we have two interfaces been defined in `pkg/types/indicator.go`: +The series interface in bbgo borrows the concept of `series` type in pinescript that allow us to query data in time-based reverse order (data that created later will be the former object in series). Right now, based on the return type, we have two interfaces been defined in [pkg/types/indicator.go](../../pkg/types/indicator.go): ```go type Series interface { @@ -25,7 +25,19 @@ type BoolSeries interface { } ``` -Series were used almost everywhere in indicators to return the calculated numeric results, while the use of BoolSeries is quite limited. At this moment, we only use BoolSeries to check if some condition is fullfilled at some timepoint. For example, in `CrossOver` and `CrossUnder` functions if `Last()` returns true, then there might be a cross event happend on the curves at the moment. +Series were used almost everywhere in indicators to return the calculated numeric results, but the use of BoolSeries is quite limited. At this moment, we only use BoolSeries to check if some condition is fullfilled at some timepoint. For example, in `CrossOver` and `CrossUnder` functions if `Last()` returns true, then there might be a cross event happend on the curves at the moment. +#### Expected Implementation +The calculation could either be done during invoke time (lazy init, for example), or pre-calculated everytime when event happens(ex: kline close). If it's done during invoke time and the computation is CPU intensive, better to cache the result somewhere inside the struct. Also remember to always implement the Series interface on indicator's struct pointer, so that access to the indicator would always point to the same memory space. +#### Compile Time Check + +We recommend developers to add the following line inside the indicator source: + +```go +var _ types.Series = &INDICATOR_TYPENAME{} +// Change INDICATOR_TYPENAME to the struct name that implements types.Series +``` + +and if any of the method in the interface not been implemented, this would generate compile time error messages.