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(), ) } // $MACD > 0 && #crossover($MACD.dea, $MACD.dif) -> long func (s *GoldX) Update(ctx ISingleSigStrategyContext) (side types.Side) { macd := ctx.Indicator("MACD", ctx.Input()) macdHist := macd.Get(0) macdDea := macd.StateSeries("dea", 0, 2) macdDif := macd.StateSeries("dif", 0, 2) // todo 包装方法 crossover/crossunder // 1.MACD DIF线接近或上穿零轴(表示整体多头市场) crossover := macdDif[0] > macdDea[0] && macdDif[1] < macdDea[1] // 上穿 crossunder := macdDif[0] < macdDea[0] && macdDif[1] > macdDea[1] // 下穿 if crossover { // 2.附加确认条件: 柱状图从负值转为正值 if macdHist > 0 { // todo 3.成交量放大(结合 OBV 等指标验证资金流入)。 return types.SideLong } } if crossunder { if macdHist < 0 { return types.SideShort } } return }