Files
banstagy/trend/t01v1.go
2026-08-24 20:53:21 +08:00

85 lines
1.9 KiB
Go

package trend
import (
"github.com/banbox/banbot/config"
"github.com/banbox/banbot/strat"
"github.com/banbox/banstagy/com"
ta "github.com/banbox/banta"
"math"
)
func calcDirt(e *ta.BarEnv) float64 {
h, l := e.High.Get(0), e.Low.Get(0)
o, c := e.Open.Get(0), e.Close.Get(0)
h1, l1 := e.High.Get(1), e.Low.Get(1)
//h2, l2 := e.High.Get(2), e.Low.Get(2)
if h == l {
return 0
}
bodyRate := math.Abs(o-c) / (h - l)
if bodyRate < 0.5 {
return 0
}
subH1, subL1 := h-h1, l-l1
//subH2, subL2 := h1-h2, l1-l2
if subH1 > 0 && subL1 > 0 {
//if math.IsNaN(subH2) || subH2 < 0 || subL2 < 0 {
// return 0
//}
//if subL2+subH2 < subH1+subL1 {
// return 1
//}
return 1
}
//else if subH1 < 0 && subL1 < 0 {
// if math.IsNaN(subH2) || subH2 > 0 || subL2 > 0 {
// return 0
// }
// if subL2+subH2 > subH1+subL1 {
// return -1
// }
// return 0
//}
return 0
}
func T01V1(pol *config.RunPolicyConfig) *strat.TradeStrat {
lenAtr := 15
baseAtrLen := int(math.Round(float64(lenAtr) * 4.3))
return &strat.TradeStrat{
Version: 1,
WarmupNum: 30,
MinTfScore: 0.75,
DrawDownExit: true,
OnStartUp: func(s *strat.StratJob) {
s.More = float64(0)
},
//OnPairInfos: common.MakePairInfos(10),
OnBar: func(s *strat.StratJob) {
e := s.Env
ma := ta.SMA(e.Close, 10).Get(0)
atr := ta.ATR(e.High, e.Low, e.Close, lenAtr)
atrBase := ta.Lowest(ta.Highest(atr, lenAtr), baseAtrLen).Get(0)
atrRate := math.Sqrt(atr.Get(0) / atrBase)
//bigDirt, _ := s.More.(float64)
c := e.Close.Get(0)
dirt := calcDirt(e)
maSub := c - ma
if s.OrderNum == 0 && dirt != 0 && maSub*dirt > 0 { // && bigDirt == dirt {
slVal := atrBase * atrRate * 0.2
slLong, slShort := c-slVal, c+slVal
com.FastOpen(s, dirt, slLong, slShort, 0)
}
},
//OnInfoBar: func(s *strategy.StratJob, e *ta.BarEnv, pair, tf string) {
// s.More = calcDirt(e)
//},
}
}