81 lines
1.7 KiB
Go
81 lines
1.7 KiB
Go
package ma1
|
|
|
|
import (
|
|
"github.com/banbox/banbot/config"
|
|
"github.com/banbox/banbot/strat"
|
|
ta "github.com/banbox/banta"
|
|
"math"
|
|
)
|
|
|
|
/*
|
|
针对15m的参数
|
|
*/
|
|
func MainV2_1(pol *config.RunPolicyConfig) *strat.TradeStrat {
|
|
periodSml = 120
|
|
periodBig = 800
|
|
parentRate = 0.5
|
|
periodParBig = int(float64(periodBig) * parentRate)
|
|
periodParSml = int(float64(periodSml) * parentRate)
|
|
return &strat.TradeStrat{
|
|
Version: 1,
|
|
WarmupNum: sampleNum*sampleStep + periodBig,
|
|
MinTfScore: 0.75,
|
|
//DrawDownExit: true,
|
|
OnStartUp: onStartUp,
|
|
//OnPairInfos: onPairInfos,
|
|
//OnInfoBar: onInfoMaSlop,
|
|
OnBar: func(s *strat.StratJob) {
|
|
e := s.Env
|
|
sml := ta.SMA(e.Close, 30)
|
|
big := ta.SMA(e.Close, 70)
|
|
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,
|
|
})
|
|
more.open = crx
|
|
//if crx == more.Dirt {
|
|
// 交叉信号和大环境一致
|
|
//openTag := "long"
|
|
//if crx < 0 {
|
|
// openTag = "short"
|
|
//}
|
|
//_ = s.OpenOrder(&strategy.EnterReq{
|
|
// Tag: openTag,
|
|
// Short: crx < 0,
|
|
//})
|
|
//}
|
|
}
|
|
prevSma := smaBig.Get(sampleStep)
|
|
if e.BarNum%sampleStep == 0 && !math.IsNaN(prevSma) {
|
|
curSma := smaBig.Get(0)
|
|
more.Slop.Update(e.BarNum, (curSma-prevSma)/curSma)
|
|
}
|
|
|
|
x = -x
|
|
if more.open != 0 && more.open == x && more.open*more.Dirt >= 0 {
|
|
more.open = 0
|
|
openTag := "long"
|
|
if x < 0 {
|
|
openTag = "short"
|
|
}
|
|
_ = s.OpenOrder(&strat.EnterReq{
|
|
Tag: openTag,
|
|
Short: x < 0,
|
|
})
|
|
}
|
|
},
|
|
}
|
|
}
|