package strategy import ( "sig-pub/pkg/types" ) // GoldX 金叉策略 type GoldX struct { ISigStrategy } func (s *GoldX) New() ISigStrategy { return &GoldX{} } func (s *GoldX) Meta() StrategyMeta { return StrategyMeta{ Name: "GoldX", Desc: "金叉策略", Input: []types.InputArg{ {Name: "fast", Type: types.InputTypeUInt, Desc: "macd快线周期"}, {Name: "slow", Type: types.InputTypeUInt, Desc: "macd慢线周期"}, {Name: "singal", Type: types.InputTypeUInt, Desc: "macd信号线周期"}, }, } } // Init 校验参数, 并根据参数初始化策略 func (s *GoldX) Init(input types.Input) (err error) { return } func (s *GoldX) CandlePeriods(ctx ISingleSigStrategyContext) int16 { return max( ctx.Indicator("macd", ctx.Input()).CandlePeriods(), ctx.Indicator("macd_dea", ctx.Input()).CandlePeriods(), ctx.Indicator("macd_hist", ctx.Input()).CandlePeriods(), ) } func (s *GoldX) Update(ctx ISingleSigStrategyContext) (side types.Side) { macd := ctx.Indicator("macd", ctx.Input()).Series(0, 2) // macd线 macdDea := ctx.Indicator("macd_dea", ctx.Input()).Series(0, 2) // macd信号线 macdHist := ctx.Indicator("macd_hist", ctx.Input()).Get(0) // macd柱状图 // todo 包装方法 crossover/crossunder // 1.MACD 线接近或上穿零轴(表示整体多头市场) crossover := macd[0] > macdDea[0] && macd[1] < macdDea[1] // 上穿 crossunder := macd[0] < macdDea[0] && macd[1] > macdDea[1] // 下穿 if crossover { // 2.附加确认条件: 柱状图从负值转为正值 if macdHist > 0 { // todo 3.成交量放大(结合 OBV 等指标验证资金流入)。 return types.SideLong } } if crossunder { if macdHist < 0 { return types.SideShort } } return }