Close a third of the position

Created at 05 Apr 2023, 23:51
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!
JA

jaydcrowe1989

Joined 11.08.2022

Close a third of the position
05 Apr 2023, 23:51


Hi,

I was wondering if someone was able to explain how I could partially close the trade please?

So for example if I have a trade and I am risking 3% of my account balance, when the trades get to 2% profit I want to close 1% (I guess 33% of the trade volume) of that trade and then leave the other 2% (66% of the trade) open.

Cheers,

Jay

 

this is my current code that doesnt seem to work:

                        double currentVolume = position.VolumeInUnits;
                        double newVolume = currentVolume * 0.66;

                        if (position.ModifyVolume(newVolume).IsSuccessful)
                        {

                                //trade partially closed - but this never seems to get here

                         }


@jaydcrowe1989
Replies

PanagiotisChar
06 Apr 2023, 08:10

Hi Jay,

You need to wrap your volume with the Symbol.NormalizeVolumeInUnits() method. See below

     double newVolume = Symbol.NormalizeVolumeInUnits(currentVolume * 0.66);

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 


@PanagiotisChar

jaydcrowe1989
06 Apr 2023, 09:42

RE:

PanagiotisChar said:

Hi Jay,

You need to wrap your volume with the Symbol.NormalizeVolumeInUnits() method. See below

     double newVolume = Symbol.NormalizeVolumeInUnits(currentVolume * 0.66);

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

Perfect, thank you!


@jaydcrowe1989