refactor rule and upper shaodw checker

This commit is contained in:
c9s 2020-06-16 14:13:53 +08:00
parent fded619772
commit 0153670f78

View File

@ -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()