Skip to content

Commit

Permalink
all: fix interval window struct usage
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Aug 24, 2022
1 parent d71fd36 commit 2e71e63
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions pkg/indicator/dema.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func (inc *DEMA) TestUpdate(value float64) *DEMA {
func (inc *DEMA) Update(value float64) {
if len(inc.Values) == 0 {
inc.SeriesBase.Series = inc
inc.a1 = &EWMA{IntervalWindow: types.IntervalWindow{inc.Interval, inc.Window}}
inc.a2 = &EWMA{IntervalWindow: types.IntervalWindow{inc.Interval, inc.Window}}
inc.a1 = &EWMA{IntervalWindow: inc.IntervalWindow}
inc.a2 = &EWMA{IntervalWindow: inc.IntervalWindow}
}

inc.a1.Update(value)
Expand Down
6 changes: 3 additions & 3 deletions pkg/indicator/hull.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ var _ types.SeriesExtend = &HULL{}
func (inc *HULL) Update(value float64) {
if inc.result == nil {
inc.SeriesBase.Series = inc
inc.ma1 = &EWMA{IntervalWindow: types.IntervalWindow{inc.Interval, inc.Window / 2}}
inc.ma2 = &EWMA{IntervalWindow: types.IntervalWindow{inc.Interval, inc.Window}}
inc.result = &EWMA{IntervalWindow: types.IntervalWindow{inc.Interval, int(math.Sqrt(float64(inc.Window)))}}
inc.ma1 = &EWMA{IntervalWindow: types.IntervalWindow{Interval: inc.Interval, Window: inc.Window / 2}}
inc.ma2 = &EWMA{IntervalWindow: inc.IntervalWindow}
inc.result = &EWMA{IntervalWindow: types.IntervalWindow{Interval: inc.Interval, Window: int(math.Sqrt(float64(inc.Window)))}}
}
inc.ma1.Update(value)
inc.ma2.Update(value)
Expand Down
6 changes: 3 additions & 3 deletions pkg/indicator/tema.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ type TEMA struct {
func (inc *TEMA) Update(value float64) {
if len(inc.Values) == 0 {
inc.SeriesBase.Series = inc
inc.A1 = &EWMA{IntervalWindow: types.IntervalWindow{inc.Interval, inc.Window}}
inc.A2 = &EWMA{IntervalWindow: types.IntervalWindow{inc.Interval, inc.Window}}
inc.A3 = &EWMA{IntervalWindow: types.IntervalWindow{inc.Interval, inc.Window}}
inc.A1 = &EWMA{IntervalWindow: inc.IntervalWindow}
inc.A2 = &EWMA{IntervalWindow: inc.IntervalWindow}
inc.A3 = &EWMA{IntervalWindow: inc.IntervalWindow}
}
inc.A1.Update(value)
a1 := inc.A1.Last()
Expand Down
12 changes: 6 additions & 6 deletions pkg/indicator/till.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ func (inc *TILL) Update(value float64) {
inc.VolumeFactor = defaultVolumeFactor
}
inc.SeriesBase.Series = inc
inc.e1 = &EWMA{IntervalWindow: types.IntervalWindow{inc.Interval, inc.Window}}
inc.e2 = &EWMA{IntervalWindow: types.IntervalWindow{inc.Interval, inc.Window}}
inc.e3 = &EWMA{IntervalWindow: types.IntervalWindow{inc.Interval, inc.Window}}
inc.e4 = &EWMA{IntervalWindow: types.IntervalWindow{inc.Interval, inc.Window}}
inc.e5 = &EWMA{IntervalWindow: types.IntervalWindow{inc.Interval, inc.Window}}
inc.e6 = &EWMA{IntervalWindow: types.IntervalWindow{inc.Interval, inc.Window}}
inc.e1 = &EWMA{IntervalWindow: inc.IntervalWindow}
inc.e2 = &EWMA{IntervalWindow: inc.IntervalWindow}
inc.e3 = &EWMA{IntervalWindow: inc.IntervalWindow}
inc.e4 = &EWMA{IntervalWindow: inc.IntervalWindow}
inc.e5 = &EWMA{IntervalWindow: inc.IntervalWindow}
inc.e6 = &EWMA{IntervalWindow: inc.IntervalWindow}
square := inc.VolumeFactor * inc.VolumeFactor
cube := inc.VolumeFactor * square
inc.c1 = -cube
Expand Down
4 changes: 2 additions & 2 deletions pkg/indicator/tma.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ func (inc *TMA) Update(value float64) {
if inc.s1 == nil {
inc.SeriesBase.Series = inc
w := (inc.Window + 1) / 2
inc.s1 = &SMA{IntervalWindow: types.IntervalWindow{inc.Interval, w}}
inc.s2 = &SMA{IntervalWindow: types.IntervalWindow{inc.Interval, w}}
inc.s1 = &SMA{IntervalWindow: types.IntervalWindow{Interval: inc.Interval, Window: w}}
inc.s2 = &SMA{IntervalWindow: types.IntervalWindow{Interval: inc.Interval, Window: w}}
}

inc.s1.Update(value)
Expand Down
2 changes: 1 addition & 1 deletion pkg/indicator/zlema.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (inc *ZLEMA) Length() int {
func (inc *ZLEMA) Update(value float64) {
if inc.lag == 0 || inc.zlema == nil {
inc.SeriesBase.Series = inc
inc.zlema = &EWMA{IntervalWindow: types.IntervalWindow{inc.Interval, inc.Window}}
inc.zlema = &EWMA{IntervalWindow: inc.IntervalWindow}
inc.lag = int((float64(inc.Window)-1.)/2. + 0.5)
}
inc.data.Push(value)
Expand Down
4 changes: 2 additions & 2 deletions pkg/strategy/bollmaker/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,8 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se

// Setup dynamic spread
if s.DynamicSpread.Enabled {
s.DynamicSpread.DynamicBidSpread = &indicator.SMA{IntervalWindow: types.IntervalWindow{s.Interval, s.DynamicSpread.Window}}
s.DynamicSpread.DynamicAskSpread = &indicator.SMA{IntervalWindow: types.IntervalWindow{s.Interval, s.DynamicSpread.Window}}
s.DynamicSpread.DynamicBidSpread = &indicator.SMA{IntervalWindow: types.IntervalWindow{Interval: s.Interval, Window: s.DynamicSpread.Window}}
s.DynamicSpread.DynamicAskSpread = &indicator.SMA{IntervalWindow: types.IntervalWindow{Interval: s.Interval, Window: s.DynamicSpread.Window}}
}

if s.DisableShort {
Expand Down

0 comments on commit 2e71e63

Please sign in to comment.