bbgo: add EMA and SMA debug var

This commit is contained in:
c9s 2021-10-18 15:23:22 +08:00
parent 721d63bee0
commit 30b82390b7

View File

@ -17,6 +17,21 @@ import (
"github.com/c9s/bbgo/pkg/util"
)
var (
debugEWMA = false
debugSMA = false
)
func init() {
if v, ok := util.GetEnvVarBool("DEBUG_EWMA"); ok {
debugEWMA = v
}
if v, ok := util.GetEnvVarBool("DEBUG_SMA"); ok {
debugSMA = v
}
}
type StandardIndicatorSet struct {
Symbol string
// Standard indicators
@ -45,9 +60,22 @@ func NewStandardIndicatorSet(symbol string, store *MarketDataStore) *StandardInd
iw := types.IntervalWindow{Interval: interval, Window: window}
set.sma[iw] = &indicator.SMA{IntervalWindow: iw}
set.sma[iw].Bind(store)
if debugSMA {
set.sma[iw].OnUpdate(func(value float64) {
log.Infof("%s SMA %s: %f", symbol, iw.String(), value)
})
}
set.ewma[iw] = &indicator.EWMA{IntervalWindow: iw}
set.ewma[iw].Bind(store)
// if debug ewma is enabled, we add the debug handler
if debugEWMA {
set.ewma[iw].OnUpdate(func(value float64) {
log.Infof("%s EWMA %s: %f", symbol, iw.String(), value)
})
}
}
// setup boll indicator, we may refactor boll indicator by subscribing SMA indicator,