2022-09-29 11:15:10 +00:00
|
|
|
package drift
|
|
|
|
|
|
|
|
func (s *Strategy) CheckStopLoss() bool {
|
|
|
|
if s.UseStopLoss {
|
2022-10-03 05:00:18 +00:00
|
|
|
stoploss := s.StopLoss.Float64()
|
2022-09-29 11:15:10 +00:00
|
|
|
if s.sellPrice > 0 && s.sellPrice*(1.+stoploss) <= s.highestPrice ||
|
|
|
|
s.buyPrice > 0 && s.buyPrice*(1.-stoploss) >= s.lowestPrice {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if s.UseAtr {
|
2023-05-31 11:35:44 +00:00
|
|
|
atr := s.atr.Last(0)
|
2022-09-29 11:15:10 +00:00
|
|
|
if s.sellPrice > 0 && s.sellPrice+atr <= s.highestPrice ||
|
|
|
|
s.buyPrice > 0 && s.buyPrice-atr >= s.lowestPrice {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|