fix closes sort
This commit is contained in:
35
internal/logic/strategy/rule/utils.go
Normal file
35
internal/logic/strategy/rule/utils.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package rule
|
||||
|
||||
// 如果数据是降序(最新在前),需要反转
|
||||
func reverseSlice(s []float64) []float64 {
|
||||
result := make([]float64, len(s))
|
||||
for i, j := 0, len(s)-1; i < len(s); i, j = i+1, j-1 {
|
||||
result[i] = s[j]
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// 检查值是否为数组最后N个元素中的最小值
|
||||
func CheckLowest(prices []float64, target int, n int) bool {
|
||||
if len(prices) == 0 || n <= 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
// 如果n大于数组长度,使用整个数组
|
||||
if n > len(prices) {
|
||||
n = len(prices)
|
||||
}
|
||||
|
||||
// 获取最后n个元素
|
||||
slice := prices[len(prices)-n:]
|
||||
|
||||
// 查找最小值
|
||||
minVal := slice[0]
|
||||
for _, val := range slice[1:] {
|
||||
if val < minVal {
|
||||
minVal = val
|
||||
}
|
||||
}
|
||||
|
||||
return target == int(minVal)
|
||||
}
|
||||
Reference in New Issue
Block a user