You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

31 lines
574 B

package strategy
// GoldX 金叉策略
type GoldX struct {
}
func (s *GoldX) New() Strategy {
return &GoldX{}
}
func (s *GoldX) Meta() StrategyMeta {
return StrategyMeta{
Name: "GoldX",
}
}
func (s *GoldX) Update(ctx StrategyContext) {
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()
}
}