mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
pivotshort: add fastpivot
This commit is contained in:
parent
4b78ba112f
commit
e23ed8c783
|
@ -38,13 +38,13 @@ type BreakLow struct {
|
||||||
|
|
||||||
FakeBreakStop *FakeBreakStop `json:"fakeBreakStop"`
|
FakeBreakStop *FakeBreakStop `json:"fakeBreakStop"`
|
||||||
|
|
||||||
lastLow fixedpoint.Value
|
lastLow, lastFastLow fixedpoint.Value
|
||||||
|
|
||||||
// lastBreakLow is the low that the price just break
|
// lastBreakLow is the low that the price just break
|
||||||
lastBreakLow fixedpoint.Value
|
lastBreakLow fixedpoint.Value
|
||||||
|
|
||||||
pivotLow *indicator.PivotLow
|
pivotLow, fastPivotLow *indicator.PivotLow
|
||||||
pivotLowPrices []fixedpoint.Value
|
pivotLowPrices []fixedpoint.Value
|
||||||
|
|
||||||
trendEWMALast, trendEWMACurrent float64
|
trendEWMALast, trendEWMACurrent float64
|
||||||
|
|
||||||
|
@ -84,8 +84,11 @@ func (s *BreakLow) Bind(session *bbgo.ExchangeSession, orderExecutor *bbgo.Gener
|
||||||
standardIndicator := session.StandardIndicatorSet(s.Symbol)
|
standardIndicator := session.StandardIndicatorSet(s.Symbol)
|
||||||
|
|
||||||
s.lastLow = fixedpoint.Zero
|
s.lastLow = fixedpoint.Zero
|
||||||
|
|
||||||
s.pivotLow = standardIndicator.PivotLow(s.IntervalWindow)
|
s.pivotLow = standardIndicator.PivotLow(s.IntervalWindow)
|
||||||
|
s.fastPivotLow = standardIndicator.PivotLow(types.IntervalWindow{
|
||||||
|
Interval: s.Interval,
|
||||||
|
Window: 3, // make it faster
|
||||||
|
})
|
||||||
|
|
||||||
if s.StopEMA != nil {
|
if s.StopEMA != nil {
|
||||||
s.StopEMA.Bind(session, orderExecutor)
|
s.StopEMA.Bind(session, orderExecutor)
|
||||||
|
@ -143,12 +146,12 @@ func (s *BreakLow) Bind(session *bbgo.ExchangeSession, orderExecutor *bbgo.Gener
|
||||||
}
|
}
|
||||||
|
|
||||||
session.MarketDataStream.OnKLineClosed(types.KLineWith(s.Symbol, types.Interval1m, func(kline types.KLine) {
|
session.MarketDataStream.OnKLineClosed(types.KLineWith(s.Symbol, types.Interval1m, func(kline types.KLine) {
|
||||||
if len(s.pivotLowPrices) == 0 {
|
if len(s.pivotLowPrices) == 0 || s.lastLow.IsZero() {
|
||||||
log.Infof("currently there is no pivot low prices, can not check break low...")
|
log.Infof("currently there is no pivot low prices, can not check break low...")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
previousLow := s.pivotLowPrices[len(s.pivotLowPrices)-1]
|
previousLow := s.lastLow
|
||||||
ratio := fixedpoint.One.Add(s.Ratio)
|
ratio := fixedpoint.One.Add(s.Ratio)
|
||||||
breakPrice := previousLow.Mul(ratio)
|
breakPrice := previousLow.Mul(ratio)
|
||||||
|
|
||||||
|
@ -266,11 +269,25 @@ func (s *BreakLow) pilotQuantityCalculation() {
|
||||||
|
|
||||||
func (s *BreakLow) updatePivotLow() bool {
|
func (s *BreakLow) updatePivotLow() bool {
|
||||||
lastLow := fixedpoint.NewFromFloat(s.pivotLow.Last())
|
lastLow := fixedpoint.NewFromFloat(s.pivotLow.Last())
|
||||||
if lastLow.IsZero() || lastLow.Compare(s.lastLow) == 0 {
|
if lastLow.IsZero() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
s.lastLow = lastLow
|
lastLowChanged := lastLow.Compare(s.lastLow) != 0
|
||||||
s.pivotLowPrices = append(s.pivotLowPrices, lastLow)
|
if lastLowChanged {
|
||||||
return true
|
s.lastLow = lastLow
|
||||||
|
s.pivotLowPrices = append(s.pivotLowPrices, lastLow)
|
||||||
|
}
|
||||||
|
|
||||||
|
lastFastLow := fixedpoint.NewFromFloat(s.fastPivotLow.Last())
|
||||||
|
if !lastFastLow.IsZero() {
|
||||||
|
if lastFastLow.Compare(s.lastLow) < 0 {
|
||||||
|
// invalidate the last low
|
||||||
|
s.lastLow = fixedpoint.Zero
|
||||||
|
lastLowChanged = false
|
||||||
|
}
|
||||||
|
s.lastFastLow = lastFastLow
|
||||||
|
}
|
||||||
|
|
||||||
|
return lastLowChanged
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user