Files
banstagy/old/breakout_v1.go
2026-08-24 20:53:21 +08:00

76 lines
1.7 KiB
Go
Raw Permalink 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 old
import (
"github.com/banbox/banbot/config"
"github.com/banbox/banbot/core"
"github.com/banbox/banbot/strat"
"github.com/banbox/banexg/log"
ta "github.com/banbox/banta"
"go.uber.org/zap"
)
/*
适合4h,收益很不稳定
*/
func BreakOutV1(pol *config.RunPolicyConfig) *strat.TradeStrat {
periodBig := 200
periodSml := 30
return &strat.TradeStrat{
Version: 1,
WarmupNum: periodBig,
MinTfScore: 0.75,
//DrawDownExit: true,
OnBar: func(s *strat.StratJob) {
e := s.Env
hhBig := ta.Highest(e.Close, periodBig).Get(1)
//llSml := ta.Lowest(e.Close, periodSml).Get(1)
llBig := ta.Lowest(e.Close, periodBig).Get(1)
//hhSml := ta.Highest(e.Close, periodSml).Get(1)
maSml := ta.SMA(e.Close, periodSml)
maBig := ta.SMA(e.Close, periodBig)
maX := maSml.Cross(maBig)
c := e.Close.Get(0)
openTag := ""
closeTag := ""
if len(s.LongOrders) == 0 && c >= hhBig {
openTag = "long"
} else if len(s.ShortOrders) == 0 && c <= llBig {
openTag = "short"
}
if maX == 1 {
closeTag = "xshort"
} else if maX == -1 {
closeTag = "xlong"
}
//if len(s.LongOrders) > 0 && c <= llSml {
// closeTag = "xlong"
//} else if len(s.ShortOrders) > 0 && c >= hhSml {
// closeTag = "xshort"
//}
if openTag != "" {
err := s.OpenOrder(&strat.EnterReq{
Tag: openTag,
Short: openTag == "short",
})
if err != nil {
log.Error("open fail", zap.Error(err))
}
}
if closeTag != "" {
dirt := core.OdDirtLong
if closeTag == "xshort" {
dirt = core.OdDirtShort
}
err := s.CloseOrders(&strat.ExitReq{
Tag: closeTag,
Dirt: dirt,
})
if err != nil {
log.Error("close fail", zap.Error(err))
}
}
},
}
}