init
This commit is contained in:
37
demo/holdSl.go
Normal file
37
demo/holdSl.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package demo
|
||||
|
||||
import (
|
||||
"github.com/banbox/banbot/config"
|
||||
"github.com/banbox/banbot/core"
|
||||
"github.com/banbox/banbot/orm/ormo"
|
||||
"github.com/banbox/banbot/strat"
|
||||
ta "github.com/banbox/banta"
|
||||
)
|
||||
|
||||
func HoldSL(pol *config.RunPolicyConfig) *strat.TradeStrat {
|
||||
return &strat.TradeStrat{
|
||||
WarmupNum: 20,
|
||||
EachMaxLong: 1,
|
||||
OnBar: func(s *strat.StratJob) {
|
||||
e := s.Env
|
||||
ma5 := ta.VWMA(e.Close, e.Volume, 5)
|
||||
ma20 := ta.VWMA(e.Close, e.Volume, 10)
|
||||
maCrx := ma5.Cross(ma20)
|
||||
atr := ta.ATR(e.High, e.Low, e.Close, 14).Get(0)
|
||||
|
||||
for _, od := range s.LongOrders {
|
||||
od.SetStopLoss(&ormo.ExitTrigger{
|
||||
Price: e.Close.Get(0) - atr*0.5,
|
||||
})
|
||||
}
|
||||
if maCrx == -1 && len(s.LongOrders) > 0 {
|
||||
s.CloseOrders(&strat.ExitReq{Tag: "exit", Dirt: core.OdDirtLong})
|
||||
} else if maCrx == 1 || len(s.LongOrders) == 0 {
|
||||
s.OpenOrder(&strat.EnterReq{
|
||||
Tag: "long",
|
||||
StopLossVal: atr * 0.5,
|
||||
})
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user