mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +00:00
refactor 1m rule with detector pattern
This commit is contained in:
parent
ad41c14521
commit
cf7760e72a
|
@ -40,16 +40,14 @@ func (k KLine) Mid() float64 {
|
|||
func (k KLine) BounceUp() bool {
|
||||
mid := k.Mid()
|
||||
trend := k.GetTrend()
|
||||
thickness := k.GetThickness()
|
||||
return trend > 0 && k.GetOpen() > mid && k.GetClose() > mid && thickness < (1.0/4.0)
|
||||
return trend > 0 && k.GetOpen() > mid && k.GetClose() > mid
|
||||
}
|
||||
|
||||
// red candle with open and close near low price
|
||||
func (k KLine) BounceDown() bool {
|
||||
mid := k.Mid()
|
||||
trend := k.GetTrend()
|
||||
thickness := k.GetThickness()
|
||||
return trend > 0 && k.GetOpen() < mid && k.GetClose() < mid && thickness < (1.0/4.0)
|
||||
return trend > 0 && k.GetOpen() < mid && k.GetClose() < mid
|
||||
}
|
||||
|
||||
func (k KLine) GetTrend() int {
|
||||
|
@ -300,6 +298,38 @@ func (k *KLineWindow) Truncate(size int) {
|
|||
*k = (*k)[end-5 : end]
|
||||
}
|
||||
|
||||
func (k KLineWindow) GetBody() float64 {
|
||||
return k.GetChange()
|
||||
}
|
||||
|
||||
func (k KLineWindow) GetThickness() float64 {
|
||||
return math.Abs(k.GetChange()) / math.Abs(k.GetMaxChange())
|
||||
}
|
||||
|
||||
func (k KLineWindow) GetUpperShadowRatio() float64 {
|
||||
return k.GetUpperShadowHeight() / math.Abs(k.GetMaxChange())
|
||||
}
|
||||
|
||||
func (k KLineWindow) GetUpperShadowHeight() float64 {
|
||||
high := k.GetHigh()
|
||||
if k.GetOpen() > k.GetClose() {
|
||||
return high - k.GetOpen()
|
||||
}
|
||||
return high - k.GetClose()
|
||||
}
|
||||
|
||||
func (k KLineWindow) GetLowerShadowRatio() float64 {
|
||||
return k.GetLowerShadowHeight() / math.Abs(k.GetMaxChange())
|
||||
}
|
||||
|
||||
func (k KLineWindow) GetLowerShadowHeight() float64 {
|
||||
low := k.GetLow()
|
||||
if k.GetOpen() < k.GetClose() {
|
||||
return k.GetOpen() - low
|
||||
}
|
||||
return k.GetClose() - low
|
||||
}
|
||||
|
||||
|
||||
func formatVolume(val float64) string {
|
||||
return strconv.FormatFloat(val, 'f', 6, 64)
|
||||
|
|
Loading…
Reference in New Issue
Block a user