Partial volume close

Created at 25 Apr 2022, 01:31
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!
IC

icollocollo

Joined 26.11.2021

Partial volume close
25 Apr 2022, 01:31


Hello guys, is it possible to prevent a modified position not to be modified again? For example if the profit is equal to stop loss * 2 and i want to close partials. 

Problem is when price comes back to stoploss *2 it closes partials again instead of going to take profit as the remaining volume.


@icollocollo
Replies

firemyst
25 Apr 2022, 09:11

Yes.

In your code set a boolean flag to indicate that you've done your modification on the position. For example, "alreadyModifiedPosition = true;"

Every time you go through your code, only enter into the part that does the position modification if the flag is set to false.

Eg:

if (!alreadyModifiedPosition)

{

   /// do your position modification

   alreadyModifiedPosition = true;

}

 

Then you just have to figure out the logic when you reset alreadyModifiedPosition back to false. Every time you start your bot? When the position is closed? Something else?

Good luck! :-)


@firemyst

icollocollo
25 Apr 2022, 10:01

RE:

firemyst said:

Yes.

In your code set a boolean flag to indicate that you've done your modification on the position. For example, "alreadyModifiedPosition = true;"

Every time you go through your code, only enter into the part that does the position modification if the flag is set to false.

Eg:

if (!alreadyModifiedPosition)

{

   /// do your position modification

   alreadyModifiedPosition = true;

}

 

Then you just have to figure out the logic when you reset alreadyModifiedPosition back to false. Every time you start your bot? When the position is closed? Something else?

Good luck! :-)

Thank you for your reply. Please check this thread for the code. An example will be of help since i already use for each position in positions.

 


@icollocollo