init
This commit is contained in:
63
trend/ma1/v1.go
Normal file
63
trend/ma1/v1.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package ma1
|
||||
|
||||
import (
|
||||
"github.com/banbox/banbot/config"
|
||||
"github.com/banbox/banbot/strat"
|
||||
"github.com/banbox/banstagy/com"
|
||||
ta "github.com/banbox/banta"
|
||||
)
|
||||
|
||||
func MainV1(pol *config.RunPolicyConfig) *strat.TradeStrat {
|
||||
periodSml = 300
|
||||
periodBig = 1800
|
||||
parentRate = 0.5
|
||||
periodParBig = int(float64(periodBig) * parentRate)
|
||||
periodParSml = int(float64(periodSml) * parentRate)
|
||||
return &strat.TradeStrat{
|
||||
Version: 1,
|
||||
WarmupNum: periodBig,
|
||||
MinTfScore: 0.75,
|
||||
//DrawDownExit: true,
|
||||
OnStartUp: onStartUp,
|
||||
OnPairInfos: com.MakePairInfos(sampleNum*sampleStep + periodParBig),
|
||||
OnInfoBar: onInfoMaCross,
|
||||
OnBar: func(s *strat.StratJob) {
|
||||
e := s.Env
|
||||
sml := ta.SMA(e.Close, 10)
|
||||
big := ta.SMA(e.Close, 50)
|
||||
x := sml.Cross(big)
|
||||
|
||||
smaSml := ta.SMA(e.Close, periodSml)
|
||||
smaBig := ta.SMA(e.Close, periodBig)
|
||||
crx := smaSml.Cross(smaBig)
|
||||
|
||||
more, _ := s.More.(*MoreType)
|
||||
if crx == 1 || crx == -1 {
|
||||
closeTag := "x_short"
|
||||
if crx < 0 {
|
||||
closeTag = "x_long"
|
||||
}
|
||||
_ = s.CloseOrders(&strat.ExitReq{
|
||||
Tag: closeTag,
|
||||
Dirt: crx * -1,
|
||||
})
|
||||
if crx == more.Dirt {
|
||||
// 交叉信号和大环境一致
|
||||
more.open = crx
|
||||
}
|
||||
}
|
||||
|
||||
if more.open != 0 && more.open == -x {
|
||||
more.open = 0
|
||||
openTag := "long"
|
||||
if x > 0 {
|
||||
openTag = "short"
|
||||
}
|
||||
_ = s.OpenOrder(&strat.EnterReq{
|
||||
Tag: openTag,
|
||||
Short: x > 0,
|
||||
})
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user