init
This commit is contained in:
58
trend/ma_cross.go
Normal file
58
trend/ma_cross.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package trend
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/banbox/banbot/config"
|
||||
"github.com/banbox/banbot/strat"
|
||||
ta "github.com/banbox/banta"
|
||||
)
|
||||
|
||||
/*
|
||||
适用4h
|
||||
*/
|
||||
|
||||
func MaCross(pol *config.RunPolicyConfig) *strat.TradeStrat {
|
||||
return &strat.TradeStrat{
|
||||
Version: 1,
|
||||
WarmupNum: 130,
|
||||
MinTfScore: 0.75,
|
||||
OnBar: func(s *strat.StratJob) {
|
||||
e := s.Env
|
||||
ma5 := ta.SMA(e.Close, 14)
|
||||
ma30 := ta.SMA(e.Close, 40)
|
||||
xnum := ma5.Cross(ma30)
|
||||
atr := ta.ATR(e.High, e.Low, e.Close, 14).Get(0)
|
||||
//ma5Val := ma5.Get(0)
|
||||
maBigVal := ma30.Get(0)
|
||||
if xnum == 1 && len(s.LongOrders) == 0 {
|
||||
err := s.OpenOrder(&strat.EnterReq{
|
||||
Tag: "enter",
|
||||
Limit: maBigVal,
|
||||
StopLoss: maBigVal - atr*2,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Printf("open fail: %s", err)
|
||||
}
|
||||
} else if xnum == -1 && len(s.LongOrders) > 0 {
|
||||
//longOd := s.LongOrders[0]
|
||||
//if maBigVal-longOd.Enter.Price > atr*2 {
|
||||
err := s.CloseOrders(&strat.ExitReq{
|
||||
Tag: "exit",
|
||||
//Limit: maBigVal,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Printf("close fail: %s", err)
|
||||
}
|
||||
//}
|
||||
}
|
||||
//else if len(s.LongOrders) > 0 {
|
||||
// c := e.Close.Get(0)
|
||||
// for _, od := range s.LongOrders {
|
||||
// if od.Status >= ormo.InOutStatusFullEnter && (c-od.Enter.Price) > atr*2 {
|
||||
// od.SetInfo(orm.OdInfoStopLoss, maBigVal)
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user