-
-
Notifications
You must be signed in to change notification settings - Fork 306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: trailing stop properly works on both long and short positions #872
Conversation
Codecov Report
@@ Coverage Diff @@
## main #872 +/- ##
==========================================
- Coverage 19.85% 19.82% -0.03%
==========================================
Files 385 385
Lines 28825 28846 +21
==========================================
- Hits 5723 5719 -4
- Misses 22563 22588 +25
Partials 539 539
Continue to review full report at Codecov.
|
pkg/bbgo/exit_trailing_stop.go
Outdated
if err != nil { | ||
return err | ||
} | ||
if (position.IsLong() && s.Side == types.SideTypeSell) || (position.IsShort() && s.Side == types.SideTypeBuy) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不過為何這邊這樣改?
因為 Long 也有可能用 sideBuy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Long 用 sidebuy 基本上一 activate 就會生效
pkg/bbgo/exit_trailing_stop.go
Outdated
case types.SideTypeSell: | ||
return price.Sub(position.AverageCost).Div(position.AverageCost), nil | ||
case types.SideTypeBoth: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add the default case too?
pkg/bbgo/exit_trailing_stop.go
Outdated
@@ -117,6 +123,12 @@ func (s *TrailingStop2) checkStopPrice(price fixedpoint.Value, position *types.P | |||
s.latestHigh = fixedpoint.Min(price, s.latestHigh) | |||
case types.SideTypeSell: | |||
s.latestHigh = fixedpoint.Max(price, s.latestHigh) | |||
case types.SideTypeBoth: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and default case?
trailing stop of type both is similar to type buy with short position, type sell with long position