File tree 2 files changed +22
-0
lines changed
2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change
1
+ package fixedpoint
2
+
3
+ type Tester func (value Value ) bool
4
+
5
+ func PositiveTester (value Value ) bool {
6
+ return value .Sign () > 0
7
+ }
8
+
9
+ func NegativeTester (value Value ) bool {
10
+ return value .Sign () < 0
11
+ }
12
+
13
+ func Filter (values []Value , f Tester ) (slice []Value ) {
14
+ for _ , v := range values {
15
+ if f (v ) {
16
+ slice = append (slice , v )
17
+ }
18
+ }
19
+ return slice
20
+ }
Original file line number Diff line number Diff line change @@ -304,6 +304,8 @@ func (s *TradeStats) update() {
304
304
sort .Sort (fixedpoint .Descending (profitsByOrder ))
305
305
sort .Sort (fixedpoint .Descending (netProfitsByOrder ))
306
306
307
+ s .Losses = fixedpoint .Filter (profitsByOrder , fixedpoint .NegativeTester )
308
+ s .Profits = fixedpoint .Filter (profitsByOrder , fixedpoint .PositiveTester )
307
309
s .LargestProfitTrade = profitsByOrder [0 ]
308
310
s .LargestLossTrade = profitsByOrder [len (profitsByOrder )- 1 ]
309
311
if s .LargestLossTrade .Sign () > 0 {
You can’t perform that action at this time.
0 commit comments