package strategy import "sig-pub/pkg/types" // SuperTrendRSI 结合super trend和rsi指标策略 type SuperTrendRSI struct { } func (s *SuperTrendRSI) New() ISigStrategy { return &SuperTrendRSI{} } func (s *SuperTrendRSI) Meta() StrategyMeta { return StrategyMeta{ Name: "SuperTrendRSI", Desc: "超级趋势结合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 *SuperTrendRSI) Init(input types.Input) (err error) { return } func (s *SuperTrendRSI) CandlePeriods(ctx ISingleSigStrategyContext) int16 { return max( ctx.Indicator("SuperTrend", types.Input{ "window": ctx.Input().Int16("trendWindow"), "mul": ctx.Input().Int16("trendMultipiler"), }).CandlePeriods(), ctx.Indicator("RSI", types.Input{"window": ctx.Input().Int16("rsiWindow")}).CandlePeriods(), ) } func (s *SuperTrendRSI) Update(ctx ISingleSigStrategyContext) (side types.Side) { superTrend := ctx.Indicator("SuperTrend", types.Input{ "window": ctx.Input().Int16("trendWindow"), "mul": ctx.Input().Int16("trendMultipiler"), }) rsi := ctx.Indicator("RSI", types.Input{"window": ctx.Input().Int16("rsiWindow")}) // 買入:SuperTrend 轉綠(綠線在價格下方)且 RSI > 50(確認動能向上) // 賣出:SuperTrend 轉紅,或 RSI < 30(超賣退出) // 風險控制:止損 3%(SuperTrend 線為參考),無固定止盈(讓利潤奔跑) trendDirections := superTrend.StateSeries("direction", 0, 2) if trendDirections[0] == 1 && trendDirections[1] == -1 { if rsi.Get(0) > 50 { return types.SideLong } } if trendDirections[0] == -1 && trendDirections[1] == 1 { if rsi.Get(0) < 30 { return types.SideShort } } return }