mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
bbgo: move rightWindow to the IntervalWindow struct
This commit is contained in:
parent
f43f9af20f
commit
469c6bfb28
|
@ -23,8 +23,8 @@ type StandardIndicatorSet struct {
|
|||
|
||||
// Standard indicators
|
||||
// interval -> window
|
||||
boll map[types.IntervalWindowBandWidth]*indicator.BOLL
|
||||
simples map[types.IntervalWindow]indicator.KLinePusher
|
||||
iwbIndicators map[types.IntervalWindowBandWidth]*indicator.BOLL
|
||||
iwIndicators map[types.IntervalWindow]indicator.KLinePusher
|
||||
|
||||
stream types.Stream
|
||||
store *MarketDataStore
|
||||
|
@ -32,33 +32,33 @@ type StandardIndicatorSet struct {
|
|||
|
||||
func NewStandardIndicatorSet(symbol string, stream types.Stream, store *MarketDataStore) *StandardIndicatorSet {
|
||||
return &StandardIndicatorSet{
|
||||
Symbol: symbol,
|
||||
store: store,
|
||||
stream: stream,
|
||||
simples: make(map[types.IntervalWindow]indicator.KLinePusher),
|
||||
boll: make(map[types.IntervalWindowBandWidth]*indicator.BOLL),
|
||||
Symbol: symbol,
|
||||
store: store,
|
||||
stream: stream,
|
||||
iwIndicators: make(map[types.IntervalWindow]indicator.KLinePusher),
|
||||
iwbIndicators: make(map[types.IntervalWindowBandWidth]*indicator.BOLL),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *StandardIndicatorSet) initAndBind(inc indicator.KLinePusher, iw types.IntervalWindow) {
|
||||
if klines, ok := s.store.KLinesOfInterval(iw.Interval); ok {
|
||||
func (s *StandardIndicatorSet) initAndBind(inc indicator.KLinePusher, interval types.Interval) {
|
||||
if klines, ok := s.store.KLinesOfInterval(interval); ok {
|
||||
for _, k := range *klines {
|
||||
inc.PushK(k)
|
||||
}
|
||||
}
|
||||
|
||||
s.stream.OnKLineClosed(types.KLineWith(s.Symbol, iw.Interval, inc.PushK))
|
||||
s.stream.OnKLineClosed(types.KLineWith(s.Symbol, interval, inc.PushK))
|
||||
}
|
||||
|
||||
func (s *StandardIndicatorSet) allocateSimpleIndicator(t indicator.KLinePusher, iw types.IntervalWindow) indicator.KLinePusher {
|
||||
inc, ok := s.simples[iw]
|
||||
inc, ok := s.iwIndicators[iw]
|
||||
if ok {
|
||||
return inc
|
||||
}
|
||||
|
||||
inc = t
|
||||
s.initAndBind(inc, iw)
|
||||
s.simples[iw] = inc
|
||||
s.initAndBind(inc, iw.Interval)
|
||||
s.iwIndicators[iw] = inc
|
||||
return t
|
||||
}
|
||||
|
||||
|
@ -112,17 +112,17 @@ func (s *StandardIndicatorSet) STOCH(iw types.IntervalWindow) *indicator.STOCH {
|
|||
// BOLL returns the bollinger band indicator of the given interval, the window and bandwidth
|
||||
func (s *StandardIndicatorSet) BOLL(iw types.IntervalWindow, bandWidth float64) *indicator.BOLL {
|
||||
iwb := types.IntervalWindowBandWidth{IntervalWindow: iw, BandWidth: bandWidth}
|
||||
inc, ok := s.boll[iwb]
|
||||
inc, ok := s.iwbIndicators[iwb]
|
||||
if !ok {
|
||||
inc = &indicator.BOLL{IntervalWindow: iw, K: bandWidth}
|
||||
s.initAndBind(inc, iw)
|
||||
s.initAndBind(inc, iw.Interval)
|
||||
|
||||
if debugBOLL {
|
||||
inc.OnUpdate(func(sma float64, upBand float64, downBand float64) {
|
||||
logrus.Infof("%s BOLL %s: sma=%f up=%f down=%f", s.Symbol, iw.String(), sma, upBand, downBand)
|
||||
})
|
||||
}
|
||||
s.boll[iwb] = inc
|
||||
s.iwbIndicators[iwb] = inc
|
||||
}
|
||||
|
||||
return inc
|
||||
|
|
|
@ -12,8 +12,6 @@ type PivotLow struct {
|
|||
|
||||
types.IntervalWindow
|
||||
|
||||
RightWindow int `json:"rightWindow"`
|
||||
|
||||
Lows types.Float64Slice
|
||||
Values types.Float64Slice
|
||||
EndTime time.Time
|
||||
|
|
|
@ -77,8 +77,11 @@ type IntervalWindow struct {
|
|||
// The interval of kline
|
||||
Interval Interval `json:"interval"`
|
||||
|
||||
// The windows size of the indicator (EWMA and SMA)
|
||||
// The windows size of the indicator (for example, EWMA and SMA)
|
||||
Window int `json:"window"`
|
||||
|
||||
// RightWindow is used by the pivot indicator
|
||||
RightWindow int `json:"rightWindow"`
|
||||
}
|
||||
|
||||
type IntervalWindowBandWidth struct {
|
||||
|
|
Loading…
Reference in New Issue
Block a user