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

27
demo/trailing_stop.go Normal file
View File

@@ -0,0 +1,27 @@
package demo
import (
"github.com/banbox/banbot/config"
"github.com/banbox/banbot/strat"
ta "github.com/banbox/banta"
)
func TrailStop(p *config.RunPolicyConfig) *strat.TradeStrat {
return &strat.TradeStrat{
WarmupNum: 100,
TimeFrames: "1h",
OnBar: func(s *strat.StratJob) {
e := s.Env
atr := ta.ATR(e.High, e.Low, e.Close, 14).Get(0)
atrPct := atr * 100 / e.Close.Get(0)
k, d, _ := ta.KDJ(e.High, e.Low, e.Close, 9, 3, 3)
kdCross := k.Cross(d)
if len(s.LongOrders) == 0 && kdCross == 1 {
s.OpenOrder(&strat.EnterReq{
Tag: "long",
CallbackPct: min(10, 5*atrPct),
})
}
},
}
}