package strategy import "sig-pub/pkg/types" // SuperTrendMacdRSI 结合super trend和rsi指标策略 type SuperTrendMacdRSI struct { } func (s *SuperTrendMacdRSI) New() ISigStrategy { return &SuperTrendMacdRSI{} } func (s *SuperTrendMacdRSI) Meta() StrategyMeta { return StrategyMeta{ Name: "SuperTrendMacdRSI", Desc: "SuperTrend + MACD + RSI 量化策略", Input: []types.InputArg{ // {Name: "trendWindow", Type: types.InputTypeUInt, Desc: "SuperTrend ATR周期"}, // {Name: "trendMultipiler", Type: types.InputTypeUInt, Desc: "SuperTrend multipiler"}, // {Name: "rsiWindow", Type: types.InputTypeUInt, Desc: "rsi周期"}, }, } } // Init 校验参数, 并根据参数初始化策略 func (s *SuperTrendMacdRSI) Init(input types.Input) (err error) { return } func (s *SuperTrendMacdRSI) CandlePeriods(ctx ISingleSigStrategyContext) int16 { return max( ctx.Indicator("SuperTrend", types.Input{"window": 10, "mul": 3}).CandlePeriods(), ctx.Indicator("RSI", 14).CandlePeriods(), ctx.Indicator("MACD", types.Input{"fast": 12, "slow": 26, "singal": 9}).CandlePeriods(), // ctx.Indicator("MacdDEA", types.Input{"fast": 12, "slow": 26, "singal": 9}).CandlePeriods(), // ctx.Indicator("MacdDEA", types.Input{"fast": 12, "slow": 26, "singal": 9}).CandlePeriods(), // ctx.Indicator("MacdDIF", types.Input{"fast": 12, "slow": 26, "singal": 9}).CandlePeriods(), 21, ) } func (s *SuperTrendMacdRSI) Update(ctx ISingleSigStrategyContext) (side types.Side) { superTrend := ctx.Indicator("SuperTrend", types.Input{"window": 10, "mul": 3}) rsi := ctx.Indicator("RSI", 14).Get(0) macd := ctx.Indicator("MACD", types.Input{"fast": 12, "slow": 26, "singal": 9}) macdHist := macd.Get(0) macdDea := macd.StateSeries("dea", 0, 2) // macd_dea信号线 macdDif := macd.StateSeries("dif", 0, 2) // macd_dif线 // macdHist := ctx.Indicator("Macd", types.Input{"fast": 12, "slow": 26, "singal": 9}).Get(0) // macd柱 // macdDea := ctx.Indicator("MacdDEA", types.Input{"fast": 12, "slow": 26, "singal": 9}).Series(0, 2) // macd_dea信号线 // macdDif := ctx.Indicator("MacdDIF", types.Input{"fast": 12, "slow": 26, "singal": 9}).Series(0, 2) // macd_dif线 crossover := macdDif[0] > macdDea[0] && macdDif[1] < macdDea[1] // 金叉 crossunder := macdDif[0] < macdDea[0] && macdDif[1] > macdDea[1] // 死叉 closeP := ctx.Get(0).CloseF64() volAvg := ctx.Series(1, 20).Vol().Avg() vol := ctx.Get(0).VolF64() trend := superTrend.Get(0) trendDirection := superTrend.State("direction", 0) // 金叉状态且正向扩张 if crossover && macdHist > 0 { // RSI 强度过滤 if rsi > 50 { // SuperTrend 趋势确认 if closeP > trend && trendDirection == 1 { // 成交量过滤 if vol > volAvg*1.5 { return types.SideLong } } } } if crossunder && macdHist < 0 { if rsi < 50 { // SuperTrend 趋势确认 if closeP < trend && trendDirection == -1 { // 成交量过滤 if vol > volAvg*1.5 { return types.SideShort } } } } _ = ` // 策略算子脚本DST, 优化golang底层不影响策略语法 st1 = sig.SuperTrend(window=10, mul=3) rsi = sig.RSI(window=14) closeAvg = close[1:10].avg() st1[0] st1[0:10] st1.direction[0] if rsi[0] > 50 ... ` return }