PR
progy85
Blocked user by Spotware at 14 Jun 2024, 13:49
0 follower(s) 0 following 18 subscription(s)
Replies

progy85
18 Nov 2021, 10:06

RE:

amusleh said:

Hi,

To get last four lost trades net profit you can filter the lost trades first then order them, after that take the last four:

var result = History.Where(trade => trade.SymbolName.Equals(SymbolName, StringComparison.OrdinalIgnoreCase) && trade.NetProfit < 0).OrderByDescending(trade => trade.EntryTime).Take(4).Sum(trade => trade.NetProfit);

 

thanks!!!


progy85
18 Nov 2021, 08:56

RE:

amusleh said:

Hi,

To get the last four values you can use OrderByDescending and Take, but on your posted sequence the values you are looking to get aren't last four.

You can first skip the last 2 values and then use Take to get the last 4 values:

var result = History.Where(trade => trade.SymbolName.Equals(SymbolName, StringComparison.OrdinalIgnoreCase)).OrderByDescending(trade => trade.EntryTime).Skip(2).Take(4).Sum(trade => trade.NetProfit);

 

Hi,

problem is because I need to skip winnings and find last 4 lost.

If I have
win 50
win 100
win 30
lost 15
lost 13
lost 17
win 15
lost 8
lost 12
lost 15
lost 20

win 13

My results must be: 8+12+15+20= 55

Also is ok if use Count. What I need to do Is check if last four trade in a row are lost:
win

lost
win
win
win
lost
lost
lost
win
win
lost
lost
lost
lost

win

I hope you will help me. Thanks!