fix closes sort
This commit is contained in:
@@ -64,7 +64,9 @@ func (r *Rsi) Run(code string) *types.RuleResult {
|
||||
return &types.RuleResult{Key: r.Key, Name: r.Name, Score: -1, Desc: "数据不足"}
|
||||
}
|
||||
|
||||
rsiResult := talib.Rsi(close, r.Args.RsiPeriod)
|
||||
newCloses := reverseSlice(close)
|
||||
|
||||
rsiResult := talib.Rsi(newCloses, r.Args.RsiPeriod)
|
||||
prveRsi := rsiResult[len(rsiResult)-2]
|
||||
lastRsi := rsiResult[len(rsiResult)-1]
|
||||
lastRsi = utils.FloatRound(lastRsi, 2)
|
||||
@@ -88,28 +90,3 @@ func (r *Rsi) Run(code string) *types.RuleResult {
|
||||
}
|
||||
return &types.RuleResult{Key: r.Key, Name: r.Name, Score: 1, Rsi: lastRsi, Desc: fmt.Sprintf("RSI=%d prveRsi=%d,跌破下轨后呈上涨趋势", lastRsiInt, prveRsiInt)}
|
||||
}
|
||||
|
||||
// 检查值是否为数组最后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)
|
||||
}
|
||||
|
||||
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