diff --git a/pkg/fixedpoint/filter.go b/pkg/fixedpoint/filter.go new file mode 100644 index 000000000..bbcfc8c8a --- /dev/null +++ b/pkg/fixedpoint/filter.go @@ -0,0 +1,20 @@ +package fixedpoint + +type Tester func(value Value) bool + +func PositiveTester(value Value) bool { + return value.Sign() > 0 +} + +func NegativeTester(value Value) bool { + return value.Sign() < 0 +} + +func Filter(values []Value, f Tester) (slice []Value) { + for _, v := range values { + if f(v) { + slice = append(slice, v) + } + } + return slice +} diff --git a/pkg/types/trade_stats.go b/pkg/types/trade_stats.go index 7be5d0390..71c746692 100644 --- a/pkg/types/trade_stats.go +++ b/pkg/types/trade_stats.go @@ -304,6 +304,8 @@ func (s *TradeStats) update() { sort.Sort(fixedpoint.Descending(profitsByOrder)) sort.Sort(fixedpoint.Descending(netProfitsByOrder)) + s.Losses = fixedpoint.Filter(profitsByOrder, fixedpoint.NegativeTester) + s.Profits = fixedpoint.Filter(profitsByOrder, fixedpoint.PositiveTester) s.LargestProfitTrade = profitsByOrder[0] s.LargestLossTrade = profitsByOrder[len(profitsByOrder)-1] if s.LargestLossTrade.Sign() > 0 {