bbgo/pkg/strategy/drift/stoploss_test.go

59 lines
1.2 KiB
Go

package drift
import (
"testing"
"git.qtrade.icu/lychiyu/bbgo/pkg/datatype/floats"
"git.qtrade.icu/lychiyu/bbgo/pkg/fixedpoint"
"git.qtrade.icu/lychiyu/bbgo/pkg/indicator"
"github.com/stretchr/testify/assert"
)
func Test_StopLossLong(t *testing.T) {
s := &Strategy{}
s.highestPrice = 30.
s.buyPrice = 30.
s.lowestPrice = 29.7
s.StopLoss = fixedpoint.NewFromFloat(0.01)
s.UseAtr = false
s.UseStopLoss = true
assert.True(t, s.CheckStopLoss())
}
func Test_StopLossShort(t *testing.T) {
s := &Strategy{}
s.lowestPrice = 30.
s.sellPrice = 30.
s.highestPrice = 30.3
s.StopLoss = fixedpoint.NewFromFloat(0.01)
s.UseAtr = false
s.UseStopLoss = true
assert.True(t, s.CheckStopLoss())
}
func Test_ATRLong(t *testing.T) {
s := &Strategy{}
s.highestPrice = 30.
s.buyPrice = 30.
s.lowestPrice = 28.7
s.UseAtr = true
s.UseStopLoss = false
s.atr = &indicator.ATR{RMA: &indicator.RMA{
Values: floats.Slice{1., 1.2, 1.3},
}}
assert.True(t, s.CheckStopLoss())
}
func Test_ATRShort(t *testing.T) {
s := &Strategy{}
s.highestPrice = 31.3
s.sellPrice = 30.
s.lowestPrice = 30.
s.UseAtr = true
s.UseStopLoss = false
s.atr = &indicator.ATR{RMA: &indicator.RMA{
Values: floats.Slice{1., 1.2, 1.3},
}}
assert.True(t, s.CheckStopLoss())
}