rsicross: add more conditions to rsicross

This commit is contained in:
c9s 2023-07-20 18:02:20 +08:00
parent 3b68d6558e
commit b250bf94bc
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 18 additions and 6 deletions

View File

@ -16,8 +16,10 @@ exchangeStrategies:
rsicross:
symbol: BTCUSDT
interval: 5m
fastWindow: 3
slowWindow: 12
fastWindow: 6
slowWindow: 18
openBelow: 30.0
closeAbove: 60.0
quantity: 0.1

View File

@ -30,6 +30,8 @@ type Strategy struct {
Interval types.Interval `json:"interval"`
SlowWindow int `json:"slowWindow"`
FastWindow int `json:"fastWindow"`
OpenBelow fixedpoint.Value `json:"openBelow"`
CloseAbove fixedpoint.Value `json:"closeAbove"`
bbgo.OpenPositionOptions
}
@ -56,6 +58,10 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
rsiCross.OnUpdate(func(v float64) {
switch indicatorv2.CrossType(v) {
case indicatorv2.CrossOver:
if s.OpenBelow.Sign() > 0 && fastRsi.Last(0) > s.OpenBelow.Float64() {
return
}
opts := s.OpenPositionOptions
opts.Long = true
@ -70,6 +76,10 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
}
case indicatorv2.CrossUnder:
if s.CloseAbove.Sign() > 0 && fastRsi.Last(0) < s.CloseAbove.Float64() {
return
}
if err := s.OrderExecutor.ClosePosition(ctx, fixedpoint.One); err != nil {
logErr(err, "failed to close position")
}