bbgo: improve trendEMA condition

This commit is contained in:
c9s 2022-09-16 01:20:48 +08:00
parent 3d7fc75e4b
commit 427723dcaf
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -20,10 +20,6 @@ type TrendEMA struct {
}
func (s *TrendEMA) Bind(session *ExchangeSession, orderExecutor *GeneralOrderExecutor) {
if s.MaxGradient == 0.0 {
s.MaxGradient = 1.0
}
symbol := orderExecutor.Position().Symbol
s.ewma = session.StandardIndicatorSet(symbol).EWMA(s.IntervalWindow)
@ -58,9 +54,13 @@ func (s *TrendEMA) GradientAllowed() bool {
return false
}
if s.MaxGradient > 0.0 && gradient < s.MaxGradient && gradient > s.MinGradient {
return true
}
if s.MaxGradient > 0.0 && gradient > s.MaxGradient {
return false
}
if s.MinGradient > 0.0 && gradient < s.MinGradient {
return false
}
return true
}