pivotshort: use new config struct stopEMA and trendEMA

This commit is contained in:
c9s 2022-07-27 01:53:53 +08:00
parent 6f64b6d08e
commit 854af6b4bd
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -37,10 +37,11 @@ type BreakLow struct {
Leverage fixedpoint.Value `json:"leverage"` Leverage fixedpoint.Value `json:"leverage"`
Quantity fixedpoint.Value `json:"quantity"` Quantity fixedpoint.Value `json:"quantity"`
StopEMARange fixedpoint.Value `json:"stopEMARange"`
StopEMA *types.IntervalWindow `json:"stopEMA"`
TrendEMA *types.IntervalWindow `json:"trendEMA"` StopEMA *StopEMA `json:"stopEMA"`
TrendEMA *TrendEMA `json:"trendEMA"`
lastLow fixedpoint.Value lastLow fixedpoint.Value
pivot *indicator.PivotLow pivot *indicator.PivotLow
@ -81,11 +82,11 @@ func (s *BreakLow) Bind(session *bbgo.ExchangeSession, orderExecutor *bbgo.Gener
s.pivot = standardIndicator.PivotLow(s.IntervalWindow) s.pivot = standardIndicator.PivotLow(s.IntervalWindow)
if s.StopEMA != nil { if s.StopEMA != nil {
s.stopEWMA = standardIndicator.EWMA(*s.StopEMA) s.stopEWMA = standardIndicator.EWMA(s.StopEMA.IntervalWindow)
} }
if s.TrendEMA != nil { 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) { session.MarketDataStream.OnKLineClosed(types.KLineWith(s.Symbol, s.TrendEMA.Interval, func(kline types.KLine) {
s.trendEWMALast = s.trendEWMACurrent s.trendEWMALast = s.trendEWMACurrent
@ -202,9 +203,9 @@ func (s *BreakLow) Bind(session *bbgo.ExchangeSession, orderExecutor *bbgo.Gener
return return
} }
emaStopShortPrice := ema.Mul(fixedpoint.One.Sub(s.StopEMARange)) emaStopShortPrice := ema.Mul(fixedpoint.One.Sub(s.StopEMA.Range))
if closePrice.Compare(emaStopShortPrice) < 0 { 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 return
} }
} }