init
This commit is contained in:
45
demo/test.go
Normal file
45
demo/test.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package demo
|
||||
|
||||
import (
|
||||
"github.com/banbox/banbot/config"
|
||||
"github.com/banbox/banbot/core"
|
||||
"github.com/banbox/banbot/strat"
|
||||
ta "github.com/banbox/banta"
|
||||
)
|
||||
|
||||
func Test(pol *config.RunPolicyConfig) *strat.TradeStrat {
|
||||
//- 超参(极简)
|
||||
highestDay := pol.DefInt("highest day", 20, core.PNorm(10, 40))
|
||||
atrN := pol.DefInt("atrn", 14, core.PNorm(10, 30))
|
||||
slNATR := pol.Def("sl natr", 2.0, core.PNorm(0.8, 4.0))
|
||||
tpNATR := pol.Def("tp natr", 2.5, core.PNorm(1.0, 5.0))
|
||||
//预热:技术指标所需长度的最大值 + 余量
|
||||
warm := max(highestDay+1, atrN+1, 20) + 2
|
||||
return &strat.TradeStrat{
|
||||
WarmupNum: warm,
|
||||
RunTimeFrames: []string{"15m"},
|
||||
HedgeOff: true,
|
||||
OnBar: func(s *strat.StratJob) {
|
||||
e := s.Env
|
||||
if e.Close.Len() <= warm {
|
||||
return
|
||||
}
|
||||
last := e.Close.Get(0)
|
||||
hhPrev := ta.Highest(e.High, highestDay).Get(1)
|
||||
atr := ta.ATR(e.High, e.Low, e.Close, atrN).Get(0)
|
||||
//仅在没有任何多单(含未成交挂单)时考虑新挂单倮京沋塑
|
||||
if len(s.LongOrders) == 0 {
|
||||
//只在价格位于前高下方时挂“突破买入"的 stop 触发单
|
||||
if last < hhPrev && atr > 0 {
|
||||
entry := hhPrev
|
||||
_ = s.OpenOrder(&strat.EnterReq{
|
||||
Tag: "Long",
|
||||
Stop: entry,
|
||||
StopLossVal: slNATR * atr,
|
||||
TakeProfitVal: tpNATR * atr,
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user