pivotshort: add pivotWindow parameter

This commit is contained in:
c9s 2022-09-16 01:23:15 +08:00
parent 427723dcaf
commit cd338f8fe2
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -12,6 +12,7 @@ import (
type MACDDivergence struct {
*indicator.MACDConfig
PivotWindow int `json:"pivotWindow"`
}
// FailedBreakHigh -- when price breaks the previous pivot low, we set a trade entry
@ -47,7 +48,7 @@ type FailedBreakHigh struct {
MACDDivergence *MACDDivergence `json:"macdDivergence"`
macd *indicator.MACD
macdTopDivergence bool
lastFailedBreakHigh, lastHigh, lastFastHigh fixedpoint.Value
@ -318,13 +319,21 @@ func (s *FailedBreakHigh) pilotQuantityCalculation() {
}
func (s *FailedBreakHigh) detectMacdDivergence() {
if s.MACDDivergence == nil {
return
}
s.macdTopDivergence = false
// macdValues := s.macd.Values
histogramValues := s.macd.Histogram
// log.Infof("histogram values: %+v", histogramValues)
pivotWindow := 3
pivotWindow := s.MACDDivergence.PivotWindow
if pivotWindow == 0 {
pivotWindow = 3
}
if len(histogramValues) < pivotWindow*2 {
log.Warnf("histogram values is not enough for finding pivots, length=%d", len(histogramValues))
return