Information on open operations

Created at 08 Jan 2024, 13:21
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!
AndreaPereira's avatar

AndreaPereira

Joined 02.12.2023

Information on open operations
08 Jan 2024, 13:21


I would like to create an indicator that shows me on the screen in a corner, for example, the profit or loss of the open position. Once the operation is closed the value returns to zero. Can you tell me the classes I should use to collect this information?? Thank you


@AndreaPereira
Replies

PanagiotisCharalampous
09 Jan 2024, 06:40

Hi there,

You can use the Positions property to achieve this. Here is an example.

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

Best regards,

Panagiotis


@PanagiotisCharalampous

AndreaPereira
09 Jan 2024, 11:45 ( Updated at: 10 Jan 2024, 06:56 )

RE: Information on open operations

Thanks, now I'll try to integrate this statement..


@AndreaPereira

AndreaPereira
09 Jan 2024, 14:11 ( Updated at: 10 Jan 2024, 06:56 )

RE: Information on open operations

It worked, there's one last problem. I noticed that sometimes it gives me the decimal value that is longer than two digits, how can I overcome this problem?

 

 

PanagiotisCharalampous said: 

Hi there,

You can use the Positions property to achieve this. Here is an example.

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

Best regards,

Panagiotis

 


@AndreaPereira

PanagiotisCharalampous
10 Jan 2024, 07:37

You can use Math.Round to round the result


@PanagiotisCharalampous

AndreaPereira
10 Jan 2024, 12:33 ( Updated at: 11 Jan 2024, 06:21 )

RE: Information on open operations

Thanks for your patience but I'm new to programming. :)

PanagiotisCharalampous said: 

You can use Math.Round to round the result

 


@AndreaPereira