This commit is contained in:
2026-08-24 20:53:21 +08:00
commit 6e78bba16a
287 changed files with 32443 additions and 0 deletions

68
llmjob/2251.go Normal file
View File

@@ -0,0 +1,68 @@
// 修复后的banbot完整策略代码
package llmjob
import (
"github.com/banbox/banbot/config"
"github.com/banbox/banbot/core"
"github.com/banbox/banbot/strat"
ta "github.com/banbox/banta"
)
func J2251(pol *config.RunPolicyConfig) *strat.TradeStrat {
// 定义可调超参数
fastPeriod := pol.DefInt("fastPeriod", 21, core.PNorm(5, 50))
slowPeriod := pol.DefInt("slowPeriod", 55, core.PNorm(30, 100))
slMultiplier := pol.Def("slMultiplier", 1.5, core.PNorm(0.8, 3))
tpMultiplier := pol.Def("tpMultiplier", 1, core.PNorm(0.5, 2.5))
atrLength := pol.DefInt("atrLength", 14, core.PNorm(7, 30))
return &strat.TradeStrat{
WarmupNum: slowPeriod, // 预热数量取较长的EMA周期
HedgeOff: true, // 单向持仓模式,与PineScript一致
RunTimeFrames: []string{"4h"},
OnBar: func(s *strat.StratJob) {
e := s.Env
// 计算技术指标
fastMA := ta.EMA(e.Close, fastPeriod)
slowMA := ta.EMA(e.Close, slowPeriod)
atr := ta.ATR(e.High, e.Low, e.Close, atrLength)
// 获取最新值
atrVal := atr.Get(0)
closePrice := e.Close.Get(0)
// 检测EMA交叉信号
//goLong := fastMA.Cross(slowMA) == 1
goShort := fastMA.Cross(slowMA) == -1
// 金叉信号:做多
//if goLong && s.OrderNum == 0 {
// // 计算止损和止盈价格
// slPrice := closePrice - atrVal*slMultiplier
// tpPrice := closePrice + atrVal*tpMultiplier*2
// s.OpenOrder(&strat.EnterReq{
// Tag: "Long",
// Short: false,
// Limit: closePrice - atrVal*slMultiplier*0.7,
// StopBars: 7,
// StopLoss: slPrice, // 做多止损价格
// TakeProfit: tpPrice, // 做多止盈价格
// })
//}
// 死叉信号:做空
if goShort && s.OrderNum == 0 {
// 计算止损和止盈价格
slPrice := closePrice + atrVal*slMultiplier
tpPrice := closePrice - atrVal*tpMultiplier
s.OpenOrder(&strat.EnterReq{
Tag: "Short",
Short: true,
StopLoss: slPrice, // 做空止损价格
TakeProfit: tpPrice, // 做空止盈价格
})
}
},
}
}