diff --git a/config/rsicross.yaml b/config/rsicross.yaml index 7ad1de435..c9108be4e 100644 --- a/config/rsicross.yaml +++ b/config/rsicross.yaml @@ -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 diff --git a/pkg/strategy/rsicross/strategy.go b/pkg/strategy/rsicross/strategy.go index dafab6ae7..eb6c055eb 100644 --- a/pkg/strategy/rsicross/strategy.go +++ b/pkg/strategy/rsicross/strategy.go @@ -26,10 +26,12 @@ type Strategy struct { Environment *bbgo.Environment Market types.Market - Symbol string `json:"symbol"` - Interval types.Interval `json:"interval"` - SlowWindow int `json:"slowWindow"` - FastWindow int `json:"fastWindow"` + Symbol string `json:"symbol"` + 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") }