mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
20 lines
462 B
Go
20 lines
462 B
Go
package drift
|
|
|
|
func (s *Strategy) CheckStopLoss() bool {
|
|
if s.UseStopLoss {
|
|
stoploss := s.StopLoss.Float64()
|
|
if s.sellPrice > 0 && s.sellPrice*(1.+stoploss) <= s.highestPrice ||
|
|
s.buyPrice > 0 && s.buyPrice*(1.-stoploss) >= s.lowestPrice {
|
|
return true
|
|
}
|
|
}
|
|
if s.UseAtr {
|
|
atr := s.atr.Last(0)
|
|
if s.sellPrice > 0 && s.sellPrice+atr <= s.highestPrice ||
|
|
s.buyPrice > 0 && s.buyPrice-atr >= s.lowestPrice {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|