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

60 lines
1.6 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package trend
import (
"github.com/banbox/banbot/config"
"github.com/banbox/banbot/strat"
ta "github.com/banbox/banta"
)
/*
基于DV2超卖且大均线上方时做多
基于RSI4百分位排名超卖,且大均线上方时做多
效果好于双均线仅做多。
DV2加入做空部分持续亏钱
RSI加入做空变化不大
*/
func DVRSI(p *config.RunPolicyConfig) *strat.TradeStrat {
return &strat.TradeStrat{
WarmupNum: 100,
RunTimeFrames: []string{"4h"},
OnBar: func(s *strat.StratJob) {
e := s.Env
c := e.Close.Get(0)
dv := ta.DV2(e.High, e.Low, e.Close, 126, 2).Get(0)
sma := ta.SMA(e.Close, 50).Get(0)
ma10 := ta.SMA(e.Close, 10).Get(0)
rsi := ta.PercentRank(ta.RSI(e.Close, 4), 126).Get(0)
atr := ta.ATR(e.High, e.Low, e.Close, 14).Get(0)
if len(s.LongOrders) > 0 {
if c < ma10 {
for _, o := range s.LongOrders {
holdNum := e.BarCount(o.EnterAt)
if holdNum > 5 {
s.CloseOrders(&strat.ExitReq{Tag: "exitL", OrderID: o.ID})
}
}
}
} else if len(s.ShortOrders) > 0 {
if c > ma10 {
for _, o := range s.ShortOrders {
holdNum := e.BarCount(o.EnterAt)
if holdNum > 5 {
s.CloseOrders(&strat.ExitReq{Tag: "exitS", OrderID: o.ID})
}
}
}
} else if dv <= 10 && c > sma {
s.OpenOrder(&strat.EnterReq{Tag: "long", StopLossVal: atr * 3})
} else if rsi < 10 && c > sma {
s.OpenOrder(&strat.EnterReq{Tag: "long", StopLossVal: atr * 3})
}
//else if rsi > 90 && c < sma {
// s.OpenOrder(&strat.EnterReq{Tag: "short", Short: true, StopLossVal: atr})
//}
},
}
}