diff --git a/pkg/bbgo/order_executor_general.go b/pkg/bbgo/order_executor_general.go index cabed33f1..afc63cdb7 100644 --- a/pkg/bbgo/order_executor_general.go +++ b/pkg/bbgo/order_executor_general.go @@ -53,7 +53,8 @@ func (e *GeneralOrderExecutor) BindTradeStats(tradeStats *types.TradeStats) { if profit == nil { return } - tradeStats.Add(profit.Profit) + + tradeStats.Add(profit) }) } diff --git a/pkg/strategy/pivotshort/strategy.go b/pkg/strategy/pivotshort/strategy.go index 60801e54c..3e011a75a 100644 --- a/pkg/strategy/pivotshort/strategy.go +++ b/pkg/strategy/pivotshort/strategy.go @@ -235,7 +235,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se } if s.TradeStats == nil { - s.TradeStats = &types.TradeStats{} + s.TradeStats = types.NewTradeStats(s.Symbol) } // StrategyController diff --git a/pkg/strategy/rsmaker/strategy.go b/pkg/strategy/rsmaker/strategy.go index 0704f8ae8..1eada96c2 100644 --- a/pkg/strategy/rsmaker/strategy.go +++ b/pkg/strategy/rsmaker/strategy.go @@ -413,7 +413,7 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo. } if s.TradeStats == nil { - s.TradeStats = &types.TradeStats{} + s.TradeStats = types.NewTradeStats(s.Symbol) } // initial required information diff --git a/pkg/strategy/support/strategy.go b/pkg/strategy/support/strategy.go index d9a37b135..126bdadfe 100644 --- a/pkg/strategy/support/strategy.go +++ b/pkg/strategy/support/strategy.go @@ -334,7 +334,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se // trade stats if s.TradeStats == nil { - s.TradeStats = &types.TradeStats{} + s.TradeStats = types.NewTradeStats(s.Symbol) } s.orderExecutor = bbgo.NewGeneralOrderExecutor(session, s.Symbol, ID, instanceID, s.Position) diff --git a/pkg/types/trade_stats.go b/pkg/types/trade_stats.go index ed459e00a..ce0281d8c 100644 --- a/pkg/types/trade_stats.go +++ b/pkg/types/trade_stats.go @@ -9,6 +9,7 @@ import ( // TODO: Add more stats from the reference: // See https://www.metatrader5.com/en/terminal/help/algotrading/testing_report type TradeStats struct { + Symbol string `json:"symbol"` WinningRatio fixedpoint.Value `json:"winningRatio" yaml:"winningRatio"` NumOfLossTrade int `json:"numOfLossTrade" yaml:"numOfLossTrade"` NumOfProfitTrade int `json:"numOfProfitTrade" yaml:"numOfProfitTrade"` @@ -22,7 +23,19 @@ type TradeStats struct { TotalNetProfit fixedpoint.Value `json:"totalNetProfit" yaml:"totalNetProfit"` } -func (s *TradeStats) Add(pnl fixedpoint.Value) { +func NewTradeStats(symbol string) *TradeStats { + return &TradeStats{Symbol: symbol} +} + +func (s *TradeStats) Add(profit *Profit) { + if profit.Symbol != s.Symbol { + return + } + + s.add(profit.Profit) +} + +func (s *TradeStats) add(pnl fixedpoint.Value) { if pnl.Sign() > 0 { s.NumOfProfitTrade++ s.Profits = append(s.Profits, pnl)