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

89 lines
2.6 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.

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 J3121(pol *config.RunPolicyConfig) *strat.TradeStrat {
// 定义可调参数
bbLength := pol.DefInt("bbLength", 20, core.PNorm(10, 50))
bbStdDev := pol.Def("bbStdDev", 1.8, core.PNorm(1.0, 3.0))
cmoLength := pol.DefInt("cmoLength", 10, core.PNorm(5, 30))
cmoOverbought := pol.Def("cmoOverbought", 45.0, core.PNorm(30.0, 70.0))
cmoOversold := pol.Def("cmoOversold", -50.0, core.PNorm(-70.0, -30.0))
return &strat.TradeStrat{
WarmupNum: bbLength, // 预热期设置为布林带周期长度
HedgeOff: true, // 单向持仓模式
EachMaxLong: 1, // 最多一个多头订单
EachMaxShort: 1, // 最多一个空头订单
RunTimeFrames: []string{"5m"},
OnBar: func(s *strat.StratJob) {
e := s.Env
// 计算布林带
bbUpper, bbBasis, bbLower := ta.BBANDS(e.Close, bbLength, bbStdDev, bbStdDev)
// 计算钱德动量振荡器
cmo := ta.CMO(e.Close, cmoLength)
// 获取当前值
closePrice := e.Close.Get(0)
cmoValue := cmo.Get(0)
bbUpperValue := bbUpper.Get(0)
bbLowerValue := bbLower.Get(0)
bbBasisValue := bbBasis.Get(0)
// 检查数据有效性
if math.IsNaN(closePrice) || math.IsNaN(cmoValue) ||
math.IsNaN(bbUpperValue) || math.IsNaN(bbLowerValue) || math.IsNaN(bbBasisValue) {
return
}
// 做多条件:价格下穿布林带下轨且CMO低于超卖阈值
longCondition := e.Close.Cross(bbLower) == -1 && cmoValue < cmoOversold
// 做空条件:价格上穿布林带上轨且CMO高于超买阈值
shortCondition := e.Close.Cross(bbUpper) == 1 && cmoValue > cmoOverbought
// 平多条件:价格上穿布林带中轨或CMO高于超买阈值
exitLong := e.Close.Cross(bbBasis) == 1 || cmoValue > cmoOverbought
// 平空条件:价格下穿布林带中轨或CMO低于超卖阈值
exitShort := e.Close.Cross(bbBasis) == -1 || cmoValue < cmoOversold
// 执行交易操作
if longCondition && len(s.LongOrders) == 0 {
s.OpenOrder(&strat.EnterReq{
Tag: "Long",
})
}
if shortCondition && len(s.ShortOrders) == 0 {
s.OpenOrder(&strat.EnterReq{
Tag: "Short",
Short: true,
})
}
if exitLong && len(s.LongOrders) > 0 {
s.CloseOrders(&strat.ExitReq{
Tag: "exit_long",
Dirt: core.OdDirtLong,
})
}
if exitShort && len(s.ShortOrders) > 0 {
s.CloseOrders(&strat.ExitReq{
Tag: "exit_short",
Dirt: core.OdDirtShort,
})
}
},
}
}