Need Help sum net profit for all closed Position

Created at 04 Nov 2021, 21:41
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
MO

mohsabry.ms

Joined 15.09.2021

Need Help sum net profit for all closed Position
04 Nov 2021, 21:41


I tired to sum every closed Position

every time it rest the value to the last net profit

I try both " lastTrade.NetProfit" and " LastResult.Position.NetProfit"

I'm working on cBot that stop at certain Netprofit

could you help me please,

Thank you in advance

Regards;


@mohsabry.ms
Replies

amusleh
05 Nov 2021, 07:35

Hi,

You can use history to sum the net profit of all your closed positions (trades):

var netProfit = History.Sum(trade => trade.NetProfit);

To get net profit of all your open positions you can use Positions:

var netProfit = Positions.Sum(position => position.NetProfit);

 


@amusleh

mohsabry.ms
05 Nov 2021, 14:41

RE: Thank you for helping

amusleh said:

Hi,

You can use history to sum the net profit of all your closed positions (trades):

var netProfit = History.Sum(trade => trade.NetProfit);

To get net profit of all your open positions you can use Positions:

var netProfit = Positions.Sum(position => position.NetProfit);

 

It works well,

Appreciate your help

Regards,

 


@mohsabry.ms

mohsabry.ms
06 Nov 2021, 01:29

RE: RE: Thank you for helping

Hi,

If I wanna to choose from history some specific closed trades that i labeled it before as "sell_today"

how to modify this code to select them only;

var netProfit = History.Sum(trade => trade.NetProfit);

 

Forgive me I'm just a beginner

Thank you in advace

Best Regards,


@mohsabry.ms

PanagiotisCharalampous
08 Nov 2021, 08:17

Hi mohsabry.ms,

Here you go

var netProfit = History.Where(trade => trade.Label == "sell_today").Sum(trade => trade.NetProfit);

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

mohsabry.ms
08 Nov 2021, 20:41

RE:

Thank you for your valuable helping

Best Regards;


@mohsabry.ms