package strategy // GoldX 金叉策略 type GoldX struct { } func (s *GoldX) New() IStrategy { return &GoldX{} } func (s *GoldX) Meta() StrategyMeta { return StrategyMeta{ Name: "GoldX", Desc: "金叉策略", } } func (s *GoldX) Update(ctx IStrategyContext) { sma14 := ctx.IndicatorW("sma", 14) sma28 := ctx.IndicatorW("sma", 28) // 包装方法 s14 := sma14.Series(0, 2) s28 := sma28.Series(0, 2) crossover := s14[0] > s28[0] && s14[1] < s28[1] // 上穿 crossunder := s14[0] < s28[0] && s14[1] > s28[1] // 下穿 if crossover { ctx.Buy() } if crossunder { ctx.Sell() } }