Files
banstagy/llmjob/3707.go
2026-08-24 20:53:21 +08:00

73 lines
1.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 修复后的banbot完整策略代码
package llmjob
import (
"github.com/banbox/banbot/config"
"github.com/banbox/banbot/core"
"github.com/banbox/banbot/strat"
ta "github.com/banbox/banta"
"math"
)
func J3707(pol *config.RunPolicyConfig) *strat.TradeStrat {
// 定义策略参数
rangeLength := pol.DefInt("rangeLength", 5, core.PNorm(3, 20))
useHeikinAshi := pol.Def("useHeikinAshi", 0.0, core.PUniform(0, 1)) // 1.0表示true,0.0表示false
return &strat.TradeStrat{
WarmupNum: rangeLength + 1, // 确保有足够的历史数据计算指标
HedgeOff: true, // 单向持仓模式
RunTimeFrames: []string{"3d"},
OnBar: func(s *strat.StratJob) {
e := s.Env
// 获取K线数据
var open, close *ta.Series
if useHeikinAshi > 0.5 {
// 使用Heikin Ashi蜡烛图
haOpen, _, _, haClose := ta.HeikinAshi(e)
open = haOpen
close = haClose
} else {
// 使用标准K线
open = e.Open
close = e.Close
}
// 计算成交量范围
highest := ta.Highest(e.Volume, rangeLength)
_ = ta.Lowest(e.Volume.Mul(-1), rangeLength) // 最低负成交量
// 获取当前值和前一个值
highestCurr := highest.Get(0)
highestPrev := highest.Get(1)
closeCurr := close.Get(0)
openCurr := open.Get(0)
// 检查数据有效性
if math.IsNaN(highestCurr) || math.IsNaN(highestPrev) || math.IsNaN(closeCurr) || math.IsNaN(openCurr) {
return
}
// 生成交易信号
volumeBreakout := highestCurr > highestPrev
isBullish := closeCurr > openCurr
isBearish := closeCurr < openCurr
// 执行交易
if volumeBreakout && isBullish {
// 成交量突破前高且为阳线,做多
s.OpenOrder(&strat.EnterReq{
Tag: "Long Entry",
})
} else if volumeBreakout && isBearish {
// 成交量突破前高且为阴线,做空
s.OpenOrder(&strat.EnterReq{
Tag: "Short Entry",
Short: true,
})
}
},
}
}