rsicross: add more conditions to rsicross

This commit is contained in:
c9s 2023-07-20 18:02:20 +08:00
parent d730bc8d41
commit ba909d857d
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: rsicross:
symbol: BTCUSDT symbol: BTCUSDT
interval: 5m interval: 5m
fastWindow: 3 fastWindow: 6
slowWindow: 12 slowWindow: 18
openBelow: 30.0
closeAbove: 60.0
quantity: 0.1 quantity: 0.1

View File

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