Skip to content
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

Merged
merged 3 commits into from
Aug 11, 2022

Conversation

andycheng123
Copy link
Collaborator

@andycheng123 andycheng123 commented Aug 11, 2022

trailing stop of type both is similar to type buy with short position, type sell with long position

@codecov
Copy link

codecov bot commented Aug 11, 2022

Codecov Report

Merging #872 (8527d49) into main (d31b812) will decrease coverage by 0.02%.
The diff coverage is 10.71%.

Impacted file tree graph

@@            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              
Impacted Files Coverage Δ
pkg/bbgo/exit_trailing_stop.go 49.10% <10.71%> (-15.73%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d31b812...8527d49. Read the comment docs.

if err != nil {
return err
}
if (position.IsLong() && s.Side == types.SideTypeSell) || (position.IsShort() && s.Side == types.SideTypeBuy) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不過為何這邊這樣改?

因為 Long 也有可能用 sideBuy

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long 用 sidebuy 基本上一 activate 就會生效

case types.SideTypeSell:
return price.Sub(position.AverageCost).Div(position.AverageCost), nil
case types.SideTypeBoth:
Copy link
Owner

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?

@@ -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:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and default case?

@andycheng123 andycheng123 merged commit 62d450b into c9s:main Aug 11, 2022
@andycheng123 andycheng123 deleted the fix/trailing-stop branch August 11, 2022 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants