From 854af6b4bd95498817f5c42a762fe1cd0588b5a9 Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 27 Jul 2022 01:53:53 +0800 Subject: [PATCH] pivotshort: use new config struct stopEMA and trendEMA --- pkg/strategy/pivotshort/breaklow.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pkg/strategy/pivotshort/breaklow.go b/pkg/strategy/pivotshort/breaklow.go index 7a2516d66..a12297099 100644 --- a/pkg/strategy/pivotshort/breaklow.go +++ b/pkg/strategy/pivotshort/breaklow.go @@ -35,12 +35,13 @@ type BreakLow struct { // limit sell price = breakLowPrice * (1 + BounceRatio) BounceRatio fixedpoint.Value `json:"bounceRatio"` - Leverage fixedpoint.Value `json:"leverage"` - Quantity fixedpoint.Value `json:"quantity"` - StopEMARange fixedpoint.Value `json:"stopEMARange"` - StopEMA *types.IntervalWindow `json:"stopEMA"` + Leverage fixedpoint.Value `json:"leverage"` + Quantity fixedpoint.Value `json:"quantity"` + + StopEMA *StopEMA `json:"stopEMA"` + + TrendEMA *TrendEMA `json:"trendEMA"` - TrendEMA *types.IntervalWindow `json:"trendEMA"` lastLow fixedpoint.Value pivot *indicator.PivotLow @@ -81,11 +82,11 @@ func (s *BreakLow) Bind(session *bbgo.ExchangeSession, orderExecutor *bbgo.Gener s.pivot = standardIndicator.PivotLow(s.IntervalWindow) if s.StopEMA != nil { - s.stopEWMA = standardIndicator.EWMA(*s.StopEMA) + s.stopEWMA = standardIndicator.EWMA(s.StopEMA.IntervalWindow) } if s.TrendEMA != nil { - s.trendEWMA = standardIndicator.EWMA(*s.TrendEMA) + s.trendEWMA = standardIndicator.EWMA(s.TrendEMA.IntervalWindow) session.MarketDataStream.OnKLineClosed(types.KLineWith(s.Symbol, s.TrendEMA.Interval, func(kline types.KLine) { s.trendEWMALast = s.trendEWMACurrent @@ -202,9 +203,9 @@ func (s *BreakLow) Bind(session *bbgo.ExchangeSession, orderExecutor *bbgo.Gener return } - emaStopShortPrice := ema.Mul(fixedpoint.One.Sub(s.StopEMARange)) + emaStopShortPrice := ema.Mul(fixedpoint.One.Sub(s.StopEMA.Range)) if closePrice.Compare(emaStopShortPrice) < 0 { - log.Infof("stopEMA protection: close price %f < EMA(%v) = %f", closePrice.Float64(), s.StopEMA, ema.Float64()) + log.Infof("stopEMA protection: close price %f < EMA(%v %f) * (1 - RANGE %f) = %f", closePrice.Float64(), s.StopEMA, ema.Float64(), s.StopEMA.Range.Float64(), emaStopShortPrice.Float64()) return } }