Closing headging trades with a profit

Created at 15 May 2020, 02: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!
WI

Willie_Dladla

Joined 15.05.2020

Closing headging trades with a profit
15 May 2020, 02:21


Hello, I'm still new in developing c bots.

Is there a way to close specific hedging positions which their profit and loss add up to 0 or more?

 

Example :

*6 buy positions 

*4 sell positions 

When all 6 buy trades are in loss, if 1 of the loosing trades  has a loss of - 10 usd.

And then all the 4 sell trades are in profit. But it happens that 1 of the winning trades has a profit  of 10+.

(I need the code to close hedging positions which add up to  0 or more.)

So it will mean now trades that will be left will be 

*5 buy trades and 3 sell trades. 

(Basically the same process over and over just to reduce loosing trades.) 

If this can be possible, I would appreciate a sample code. 

Thank you in advance. 

 


@Willie_Dladla
Replies

PanagiotisCharalampous
15 May 2020, 08:37

Hi willyvusi04,

You can try something like the below

           if (Positions.Sum(x => x.NetProfit) > 0)
            {
                foreach (var position in Positions)
                    position.Close();
            }

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

Willie_Dladla
15 May 2020, 09:46

RE:

PanagiotisCharalampous said:

Hi willyvusi04,

You can try something like the below

           if (Positions.Sum(x => x.NetProfit) > 0)
            {
                foreach (var position in Positions)
                    position.Close();
            }

Best Regards,

Panagiotis 

Join us on Telegram

 

Thank you so much


@Willie_Dladla