Files
banstagy/ptn/hammer/v1.go
2026-08-24 20:53:21 +08:00

46 lines
1.0 KiB
Go

package hammer
import (
"fmt"
"github.com/banbox/banbot/config"
"github.com/banbox/banbot/strat"
ta "github.com/banbox/banta"
"math"
)
const v1AtrLen = 14
func MainV1(pol *config.RunPolicyConfig) *strat.TradeStrat {
return &strat.TradeStrat{
Version: 1,
WarmupNum: 30,
MinTfScore: 0.75,
DrawDownExit: true,
OnBar: func(s *strat.StratJob) {
e := s.Env
ma5 := ta.SMA(e.Close, 5).Get(0)
atr := ta.ATR(e.High, e.Low, e.Close, v1AtrLen)
baseAtrLen := int(math.Round(float64(v1AtrLen) * 4.3))
atrBase := ta.Lowest(ta.Highest(atr, v1AtrLen), baseAtrLen).Get(0)
if math.IsNaN(atrBase) {
return
}
o, h, l, c := e.Open.Get(0), e.High.Get(0), e.Low.Get(0), e.Close.Get(0)
solid := math.Abs(o - c)
btm := min(o, c) - l
up := h - max(o, c)
if btm > max(2.0*solid, up*5.0, atrBase*3) && c < ma5 {
stopLoss := c - atr.Get(0)*3.0
err := s.OpenOrder(&strat.EnterReq{
Tag: "long",
StopLoss: stopLoss,
})
if err != nil {
fmt.Printf("open fail %v", err)
}
}
},
}
}