init
This commit is contained in:
89
old/xem4o.go
Normal file
89
old/xem4o.go
Normal file
@@ -0,0 +1,89 @@
|
||||
package old
|
||||
|
||||
import (
|
||||
"github.com/banbox/banbot/config"
|
||||
"github.com/banbox/banbot/exg"
|
||||
"github.com/banbox/banbot/orm/ormo"
|
||||
"github.com/banbox/banbot/strat"
|
||||
ta "github.com/banbox/banta"
|
||||
"math"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
/*
|
||||
这是针对XEM/USDT:USDT的策略,其最小价格变动0.6%,挂单等待成交盈利很稳定。
|
||||
但实盘时实际成交量很小,挂单十几分钟才吃进去。
|
||||
*/
|
||||
|
||||
func xem40(p *config.RunPolicyConfig) *strat.TradeStrat {
|
||||
lenAtr := 14
|
||||
return &strat.TradeStrat{
|
||||
WarmupNum: 300,
|
||||
MinTfScore: 0.3,
|
||||
EachMaxLong: 1,
|
||||
EachMaxShort: 1,
|
||||
OnStartUp: func(s *strat.StratJob) {
|
||||
pip, err := exg.Default.PriceOnePip(s.Symbol.Symbol)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
s.More = pip
|
||||
},
|
||||
OnBar: func(s *strat.StratJob) {
|
||||
e := s.Env
|
||||
c := e.Close.Get(0)
|
||||
pip := s.More.(float64)
|
||||
if pip/c < 0.002 {
|
||||
// 仅针对XEM,最小价格变动是0.6%
|
||||
return
|
||||
}
|
||||
volMa := ta.SMA(e.Volume, 14).Get(0)
|
||||
maSml := ta.SMA(e.Close, 50).Get(0)
|
||||
maBig := ta.SMA(e.Close, 300).Get(0)
|
||||
rsi := ta.RSI50(e.Close, 50).Get(0)
|
||||
atr := ta.ATR(e.High, e.Low, e.Close, lenAtr).Get(0)
|
||||
|
||||
if s.OrderNum > 0 {
|
||||
var od *ormo.InOutOrder
|
||||
if len(s.LongOrders) > 0 {
|
||||
od = s.LongOrders[0]
|
||||
} else {
|
||||
od = s.ShortOrders[0]
|
||||
}
|
||||
if od.Status == ormo.InOutStatusPartEnter && (e.TimeStop-od.RealEnterMS())/e.TFMSecs > 3 {
|
||||
s.CloseOrders(&strat.ExitReq{Tag: "cancel", UnFillOnly: true})
|
||||
}
|
||||
return
|
||||
}
|
||||
sub1, sub2 := c-maSml, maSml-maBig
|
||||
dirt := 0
|
||||
if sub1*sub2 <= 0 && math.Abs(sub2) < atr {
|
||||
// 震荡行情
|
||||
if rsi > 3 {
|
||||
dirt = -1
|
||||
} else if rsi < -3 {
|
||||
dirt = 1
|
||||
}
|
||||
}
|
||||
if dirt == 0 && math.Abs(sub2) < pip {
|
||||
// 波动很小,直接开单
|
||||
dirt = 1
|
||||
if c > maSml {
|
||||
dirt = -1
|
||||
}
|
||||
}
|
||||
if dirt != 0 {
|
||||
amt := min(volMa*0.1, config.StakeAmount/c)
|
||||
s.OpenOrder(&strat.EnterReq{
|
||||
Tag: strconv.Itoa(dirt),
|
||||
Short: dirt < 0,
|
||||
Limit: c,
|
||||
Amount: amt,
|
||||
StopLossVal: pip * 2,
|
||||
TakeProfitVal: pip,
|
||||
StopBars: 20,
|
||||
})
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user