mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
pivotshort: use new config struct stopEMA and trendEMA
This commit is contained in:
parent
6f64b6d08e
commit
854af6b4bd
|
@ -37,10 +37,11 @@ type BreakLow struct {
|
|||
|
||||
Leverage fixedpoint.Value `json:"leverage"`
|
||||
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
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user