mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
pivotshort: improve useQuantityOrBaseBalance and add bounce short check
This commit is contained in:
parent
4d862a4286
commit
1557423229
|
@ -130,10 +130,14 @@ func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
|
|||
}
|
||||
|
||||
func (s *Strategy) useQuantityOrBaseBalance(quantity fixedpoint.Value) fixedpoint.Value {
|
||||
balance, hasBalance := s.session.Account.Balance(s.Market.BaseCurrency)
|
||||
|
||||
if hasBalance {
|
||||
if quantity.IsZero() {
|
||||
if balance, ok := s.session.Account.Balance(s.Market.BaseCurrency); ok {
|
||||
bbgo.Notify("sell quantity is not set, submitting sell with all base balance: %s", balance.Available.String())
|
||||
quantity = balance.Available
|
||||
} else {
|
||||
quantity = fixedpoint.Min(quantity, balance.Available)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -240,6 +244,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
|||
method.Bind(session, s.orderExecutor)
|
||||
}
|
||||
|
||||
if s.BounceShort != nil && s.BounceShort.Enabled {
|
||||
session.UserDataStream.OnStart(func() {
|
||||
lastKLine := s.preloadPivot(s.pivot, store)
|
||||
|
||||
|
@ -271,6 +276,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
|||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Always check whether you can open a short position or not
|
||||
session.MarketDataStream.OnKLineClosed(func(kline types.KLine) {
|
||||
|
|
|
@ -31,6 +31,9 @@ func (s *TradeStats) Add(pnl fixedpoint.Value) {
|
|||
s.MostLossTrade = fixedpoint.Min(s.MostLossTrade, pnl)
|
||||
}
|
||||
|
||||
// The win/loss ratio is your wins divided by your losses.
|
||||
// In the example, suppose for the sake of simplicity that 60 trades were winners, and 40 were losers.
|
||||
// Your win/loss ratio would be 60/40 = 1.5. That would mean that you are winning 50% more often than you are losing.
|
||||
if s.NumOfLossTrade == 0 && s.NumOfProfitTrade > 0 {
|
||||
s.WinningRatio = fixedpoint.One
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue
Block a user