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

54 lines
1.4 KiB
Go
Raw 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 (
"fmt"
"github.com/banbox/banbot/config"
"github.com/banbox/banbot/core"
"github.com/banbox/banbot/strat"
ta "github.com/banbox/banta"
)
/*
来自视频号:落升聊股:周K线+CCI指标,操作简单,只看执行力
适用于4H,48品种,210101-241101,收益725%,回撤23%,夏普5.14
熊市期间有回撤
*/
func CciMa(p *config.RunPolicyConfig) *strat.TradeStrat {
cciLen := p.DefInt("cciLen", 89, core.PNorm(50, 200))
maLen := p.DefInt("maLen", 20, core.PNorm(10, 40))
tpRate := p.Def("tpRate", 3, core.PNorm(1, 5))
slRate := p.Def("slRate", 2, core.PNorm(1, 3))
return &strat.TradeStrat{
WarmupNum: 100,
OnBar: func(s *strat.StratJob) {
e := s.Env
c := e.Close.Get(0)
cci := ta.CCI(e.Close, cciLen).Get(0)
ma := ta.SMA(e.Close, maLen).Get(0)
atr := ta.ATR(e.High, e.Low, e.Close, 14).Get(0)
dirt := float64(0)
if c > ma && cci > 0 && len(s.LongOrders) == 0 {
dirt = 1
} else if c < ma && cci < 0 && len(s.ShortOrders) == 0 {
dirt = -1
}
if dirt != 0 {
sl := atr * slRate
tp := sl * tpRate
//limit, sl, tp := atr*0.7, atr*3, atr*9
//if dirt < 0 {
// limit, sl, tp = atr*0.2, atr*1.6, atr*4
//}
s.OpenOrder(&strat.EnterReq{
Tag: fmt.Sprintf("%v", dirt),
//Limit: c - limit*dirt,
Short: dirt < 0,
StopLossVal: sl,
TakeProfitVal: tp,
})
}
},
}
}