mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
trailingstop: add default case
This commit is contained in:
parent
8d3dfd17c7
commit
8527d4996e
|
@ -80,7 +80,7 @@ func (s *TrailingStop2) getRatio(price fixedpoint.Value, position *types.Positio
|
|||
return position.AverageCost.Sub(price).Div(position.AverageCost), nil
|
||||
case types.SideTypeSell:
|
||||
return price.Sub(position.AverageCost).Div(position.AverageCost), nil
|
||||
case types.SideTypeBoth:
|
||||
default:
|
||||
if position.IsLong() {
|
||||
return price.Sub(position.AverageCost).Div(position.AverageCost), nil
|
||||
} else if position.IsShort() {
|
||||
|
@ -123,7 +123,7 @@ 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:
|
||||
default:
|
||||
if position.IsLong() {
|
||||
s.latestHigh = fixedpoint.Max(price, s.latestHigh)
|
||||
} else if position.IsShort() {
|
||||
|
@ -149,7 +149,7 @@ func (s *TrailingStop2) checkStopPrice(price fixedpoint.Value, position *types.P
|
|||
// submit order
|
||||
return s.triggerStop(price)
|
||||
}
|
||||
case types.SideTypeBoth:
|
||||
default:
|
||||
if position.IsLong() {
|
||||
change := s.latestHigh.Sub(price).Div(s.latestHigh)
|
||||
if change.Compare(s.CallbackRate) >= 0 {
|
||||
|
|
Loading…
Reference in New Issue
Block a user