Files
banstagy/trend/smp1.go
2026-08-24 20:53:21 +08:00

120 lines
2.8 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 trend
import (
"github.com/banbox/banbot/config"
"github.com/banbox/banbot/core"
"github.com/banbox/banbot/orm/ormo"
"github.com/banbox/banbot/strat"
ta "github.com/banbox/banta"
)
/*
测试仅c<h1时有明显收益,其他如l1,c1,hlc1等,收益都不够好
初始策略:日线级别,c<h1,tr>atr时开多,持有一日平仓
*/
func smp1(p *config.RunPolicyConfig) *strat.TradeStrat {
allowOpen := false
return &strat.TradeStrat{
WarmupNum: 10,
RunTimeFrames: []string{"4h"},
OnPairInfos: func(s *strat.StratJob) []*strat.PairSub {
return []*strat.PairSub{
{"_cur_", "1d", 30},
}
},
OnSymbols: func(items []string) []string {
hasBTC := false
for _, it := range items {
if it == "BTC/USDT:USDT" {
hasBTC = true
}
}
if !hasBTC {
return append([]string{"BTC/USDT:USDT"}, items...)
}
return items
},
OnStartUp: func(s *strat.StratJob) {
s.More = 0
},
OnBar: func(s *strat.StratJob) {
e := s.Env
atr := ta.ATR(e.High, e.Low, e.Close, 14).Get(0)
doOpen := s.More.(int)
c := e.Close.Get(0)
o := e.Open.Get(0)
if len(s.LongOrders) > 0 {
slPrice := c - atr*3
for _, od := range s.LongOrders {
holdNum := e.BarCount(od.EnterAt)
if holdNum < 8 {
continue
}
sl := od.GetStopLoss()
if sl == nil && (c-od.InitPrice < atr*3 || o >= c-atr*0.6) {
s.CloseOrders(&strat.ExitReq{
Tag: "exit",
OrderID: od.ID,
})
} else if sl == nil || slPrice > sl.Price {
od.SetStopLoss(&ormo.ExitTrigger{
Price: slPrice,
})
}
}
} else if doOpen == 1 {
s.More = 0
s.OpenOrder(&strat.EnterReq{
Tag: "long1",
})
}
},
OnInfoBar: func(s *strat.StratJob, e *ta.BarEnv, pair, tf string) {
if pair == "BTC/USDT:USDT" {
ma30 := ta.SMA(e.Close, 45).Get(0)
c := e.Close.Get(0)
allowOpen = c > ma30
}
c := e.Close.Get(0)
h1 := e.High.Get(1)
atr := ta.ATR(e.High, e.Low, e.Close, 14).Get(0)
tr := ta.TR(e.High, e.Low, e.Close).Get(0)
ma := ta.SMA(e.Close, 14).Get(0)
if allowOpen && len(s.LongOrders) == 0 && c < h1-atr*0.4 && c > ma {
if tr > atr {
s.More = 1
}
}
},
}
}
func smp0(p *config.RunPolicyConfig) *strat.TradeStrat {
return &strat.TradeStrat{
WarmupNum: 30,
RunTimeFrames: []string{"1d"},
OnBar: func(s *strat.StratJob) {
e := s.Env
c := e.Close.Get(0)
h1 := e.High.Get(1)
atr := ta.ATR(e.High, e.Low, e.Close, 14).Get(0)
tr := ta.TR(e.High, e.Low, e.Close).Get(0)
ma := ta.SMA(e.Close, 14).Get(0)
if len(s.LongOrders) > 0 {
s.CloseOrders(&strat.ExitReq{
Tag: "exit",
Dirt: core.OdDirtLong,
})
} else if c < h1-atr*0.4 && c > ma {
if tr > atr {
s.OpenOrder(&strat.EnterReq{
Tag: "long1",
TakeProfitVal: atr * 2,
})
}
}
},
}
}