mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
bbgo: add EMA and SMA debug var
This commit is contained in:
parent
721d63bee0
commit
30b82390b7
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue
Block a user