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.
64 lines
1.5 KiB
64 lines
1.5 KiB
package strategy |
|
|
|
import ( |
|
"math" |
|
"sig-pub/pkg/types" |
|
"sig-pub/pkg/zlog" |
|
) |
|
|
|
// CrossStar |
|
type CrossStar struct { |
|
ISigStrategy |
|
IIntervalSigStrategy |
|
rate float64 |
|
rate2 float64 |
|
} |
|
|
|
func (s *CrossStar) New() ISigStrategy { |
|
return &CrossStar{} |
|
} |
|
|
|
func (s *CrossStar) Meta() StrategyMeta { |
|
return StrategyMeta{ |
|
Name: "CrossStar", |
|
Desc: "十字星策略", |
|
Args: []Param{ |
|
{Name: "rate", Type: ParamTypeUFloat, Desc: "上线影线与基线比例"}, |
|
{Name: "rate2", Type: ParamTypeUFloat, Desc: "上线影线之间比例"}, |
|
}, |
|
} |
|
} |
|
|
|
func (s *CrossStar) Init(param StrategyParam) (err error) { // 校验参数, 并根据参数初始化策略 |
|
if s.rate, err = param.GetFloat64E("rate"); err != nil { |
|
return |
|
} |
|
if s.rate2, err = param.GetFloat64E("rate2"); err != nil { |
|
return |
|
} |
|
return |
|
} |
|
|
|
func (s *CrossStar) MaxWindow() int { |
|
return int(1) |
|
} |
|
|
|
func (s *CrossStar) Update(ctx ISigStrategyContext) (side types.Side) { |
|
// O 109744.8 H 110600 L 109507.5 C 109686.8 |
|
k0 := ctx.Get(0) |
|
open, close, high, low := k0.OpenF64(), k0.CloseF64(), k0.HighF64(), k0.LowF64() |
|
base := math.Abs(open - close) // 58 |
|
rup := (high - max(open, close)) / base // 855.2 / 2 427.6 |
|
rdown := (min(open, close) - low) / base // 179.3 / 2 89.65 |
|
|
|
if k0.Ts == 1761833700000 { |
|
zlog.Debugf("base=%.4f, rup=%.4f, rdown=%.4f", base, rup, rdown) |
|
} |
|
if rup > s.rate && rup/rdown > s.rate2 { |
|
return types.SideLong |
|
} |
|
if rdown > s.rate && rdown/rup > s.rate2 { |
|
return types.SideShort |
|
} |
|
return |
|
}
|
|
|