mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +00:00
pivotshort: rename pivotLength to window and update indicator manually
This commit is contained in:
parent
91b9605884
commit
46450c0122
|
@ -11,8 +11,12 @@ exchangeStrategies:
|
||||||
- on: binance
|
- on: binance
|
||||||
pivotshort:
|
pivotshort:
|
||||||
symbol: ETHUSDT
|
symbol: ETHUSDT
|
||||||
|
|
||||||
|
# interval is the main pivot interval
|
||||||
interval: 5m
|
interval: 5m
|
||||||
pivotLength: 200
|
|
||||||
|
# window is the main pivot window
|
||||||
|
window: 200
|
||||||
|
|
||||||
# breakLow settings are used for shorting when the current price break the previous low
|
# breakLow settings are used for shorting when the current price break the previous low
|
||||||
breakLow:
|
breakLow:
|
||||||
|
@ -53,7 +57,7 @@ exchangeStrategies:
|
||||||
|
|
||||||
# roiTakeProfitPercentage is used to force taking profit by percentage of the position ROI (currently the price change)
|
# roiTakeProfitPercentage is used to force taking profit by percentage of the position ROI (currently the price change)
|
||||||
# force to take the profit ROI exceeded the percentage.
|
# force to take the profit ROI exceeded the percentage.
|
||||||
roiTakeProfitPercentage: 10%
|
roiTakeProfitPercentage: 25%
|
||||||
|
|
||||||
# roiMinTakeProfitPercentage applies to lowerShadowRatio and cumulatedVolume exit options
|
# roiMinTakeProfitPercentage applies to lowerShadowRatio and cumulatedVolume exit options
|
||||||
roiMinTakeProfitPercentage: 10%
|
roiMinTakeProfitPercentage: 10%
|
||||||
|
|
|
@ -13,8 +13,7 @@ exchangeStrategies:
|
||||||
pivotshort:
|
pivotshort:
|
||||||
symbol: GMTBUSD
|
symbol: GMTBUSD
|
||||||
interval: 5m
|
interval: 5m
|
||||||
|
window: 120
|
||||||
pivotLength: 120
|
|
||||||
|
|
||||||
entry:
|
entry:
|
||||||
immediate: true
|
immediate: true
|
||||||
|
|
|
@ -14,7 +14,7 @@ exchangeStrategies:
|
||||||
symbol: GMTUSDT
|
symbol: GMTUSDT
|
||||||
interval: 5m
|
interval: 5m
|
||||||
|
|
||||||
pivotLength: 120
|
window: 120
|
||||||
|
|
||||||
# breakLow settings are used for shorting when the current price break the previous low
|
# breakLow settings are used for shorting when the current price break the previous low
|
||||||
breakLow:
|
breakLow:
|
||||||
|
@ -33,13 +33,18 @@ exchangeStrategies:
|
||||||
# force to take the profit ROI exceeded the percentage.
|
# force to take the profit ROI exceeded the percentage.
|
||||||
roiTakeProfitPercentage: 25%
|
roiTakeProfitPercentage: 25%
|
||||||
|
|
||||||
|
# roiMinTakeProfitPercentage applies to lowerShadowRatio and cumulatedVolume exit options
|
||||||
|
roiMinTakeProfitPercentage: 10%
|
||||||
|
|
||||||
# lowerShadowRatio is used to force taking profit when the (lower shadow height / low price) > lowerShadowRatio
|
# lowerShadowRatio is used to force taking profit when the (lower shadow height / low price) > lowerShadowRatio
|
||||||
# you can grab a simple stats by the following SQL:
|
# you can grab a simple stats by the following SQL:
|
||||||
# SELECT ((close - low) / close) AS shadow_ratio FROM binance_klines WHERE symbol = 'ETHUSDT' AND `interval` = '5m' AND start_time > '2022-01-01' ORDER BY shadow_ratio DESC LIMIT 20;
|
# SELECT ((close - low) / close) AS shadow_ratio FROM binance_klines WHERE symbol = 'ETHUSDT' AND `interval` = '5m' AND start_time > '2022-01-01' ORDER BY shadow_ratio DESC LIMIT 20;
|
||||||
lowerShadowRatio: 3%
|
lowerShadowRatio: 3%
|
||||||
|
|
||||||
|
# cumulatedVolume is used to take profit when the cumulated quote volume from the klines exceeded a threshold
|
||||||
cumulatedVolume:
|
cumulatedVolume:
|
||||||
minVolume: 50_000
|
enabled: false
|
||||||
|
minQuoteVolume: 90_000_000
|
||||||
window: 5
|
window: 5
|
||||||
|
|
||||||
marginOrderSideEffect: repay
|
marginOrderSideEffect: repay
|
||||||
|
|
|
@ -109,15 +109,15 @@ type Strategy struct {
|
||||||
Environment *bbgo.Environment
|
Environment *bbgo.Environment
|
||||||
Symbol string `json:"symbol"`
|
Symbol string `json:"symbol"`
|
||||||
Market types.Market
|
Market types.Market
|
||||||
Interval types.Interval `json:"interval"`
|
|
||||||
|
// pivot interval and window
|
||||||
|
types.IntervalWindow
|
||||||
|
|
||||||
// persistence fields
|
// persistence fields
|
||||||
Position *types.Position `json:"position,omitempty" persistence:"position"`
|
Position *types.Position `json:"position,omitempty" persistence:"position"`
|
||||||
ProfitStats *types.ProfitStats `json:"profitStats,omitempty" persistence:"profit_stats"`
|
ProfitStats *types.ProfitStats `json:"profitStats,omitempty" persistence:"profit_stats"`
|
||||||
TradeStats *TradeStats `persistence:"trade_stats"`
|
TradeStats *TradeStats `persistence:"trade_stats"`
|
||||||
|
|
||||||
PivotLength int `json:"pivotLength"`
|
|
||||||
|
|
||||||
BreakLow BreakLow `json:"breakLow"`
|
BreakLow BreakLow `json:"breakLow"`
|
||||||
Entry Entry `json:"entry"`
|
Entry Entry `json:"entry"`
|
||||||
Exit Exit `json:"exit"`
|
Exit Exit `json:"exit"`
|
||||||
|
@ -279,9 +279,8 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
||||||
})
|
})
|
||||||
s.tradeCollector.BindStream(session.UserDataStream)
|
s.tradeCollector.BindStream(session.UserDataStream)
|
||||||
|
|
||||||
iw := types.IntervalWindow{Window: s.PivotLength, Interval: s.Interval}
|
|
||||||
store, _ := session.MarketDataStore(s.Symbol)
|
store, _ := session.MarketDataStore(s.Symbol)
|
||||||
s.pivot = &indicator.Pivot{IntervalWindow: iw}
|
s.pivot = &indicator.Pivot{IntervalWindow: s.IntervalWindow}
|
||||||
s.pivot.Bind(store)
|
s.pivot.Bind(store)
|
||||||
|
|
||||||
standardIndicator, _ := session.StandardIndicatorSet(s.Symbol)
|
standardIndicator, _ := session.StandardIndicatorSet(s.Symbol)
|
||||||
|
@ -293,12 +292,16 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
||||||
|
|
||||||
session.UserDataStream.OnStart(func() {
|
session.UserDataStream.OnStart(func() {
|
||||||
if klines, ok := store.KLinesOfInterval(s.Interval); ok {
|
if klines, ok := store.KLinesOfInterval(s.Interval); ok {
|
||||||
s.pivot.Update(*klines)
|
last := (*klines)[len(*klines)-1]
|
||||||
|
log.Debugf("updating pivot indicator: %d klines", len(*klines))
|
||||||
|
for i := s.pivot.Window; i < len(*klines); i++ {
|
||||||
|
s.pivot.Update((*klines)[0 : i+1])
|
||||||
|
}
|
||||||
|
|
||||||
log.Infof("found previous lows: %v", s.pivot.Lows)
|
log.Infof("current %s price: %f", s.Symbol, last.Close.Float64())
|
||||||
log.Infof("found previous highs: %v", s.pivot.Highs)
|
log.Infof("found %s previous lows: %v", s.Symbol, s.pivot.Lows)
|
||||||
|
log.Infof("found %s previous highs: %v", s.Symbol, s.pivot.Highs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// s.placeBounceSellOrders(ctx, limitPrice, price, orderExecutor)
|
// s.placeBounceSellOrders(ctx, limitPrice, price, orderExecutor)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user