From 0153670f78f5530ac00ed4e221ca289f2ba8e0ff Mon Sep 17 00:00:00 2001 From: c9s Date: Tue, 16 Jun 2020 14:13:53 +0800 Subject: [PATCH] refactor rule and upper shaodw checker --- bbgo/kline.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/bbgo/kline.go b/bbgo/kline.go index 54d85393f..bad97f8c0 100644 --- a/bbgo/kline.go +++ b/bbgo/kline.go @@ -87,6 +87,10 @@ func (k KLine) GetThickness() float64 { return math.Abs(k.GetChange()) / math.Abs(k.GetMaxChange()) } +func (k KLine) GetUpperShadowRatio() float64 { + return k.GetUpperShadowHeight() / math.Abs(k.GetMaxChange()) +} + func (k KLine) GetUpperShadowHeight() float64 { high := k.GetHigh() if k.GetOpen() > k.GetClose() { @@ -95,6 +99,10 @@ func (k KLine) GetUpperShadowHeight() float64 { return high - k.GetClose() } +func (k KLine) GetLowerShadowRatio() float64 { + return k.GetLowerShadowHeight() / math.Abs(k.GetMaxChange()) +} + func (k KLine) GetLowerShadowHeight() float64 { low := k.GetLow() if k.GetOpen() < k.GetClose() { @@ -161,6 +169,25 @@ func (k KLineWindow) GetMaxChange() float64 { return k.GetHigh() - k.GetLow() } +func (k KLineWindow) AllDrop() bool { + for _, n := range k { + if n.GetTrend() >= 0 { + return false + } + } + return true +} + +func (k KLineWindow) AllRise() bool { + for _, n := range k { + if n.GetTrend() <= 0 { + return false + } + } + return true +} + + func (k KLineWindow) GetTrend() int { o := k.GetOpen() c := k.GetClose()