PendingOrder.ModifyVolume() removes existing stop loss and take profit

Created at 04 Nov 2024, 11:48
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!
ER

erik.lindblad

Joined 05.03.2019

PendingOrder.ModifyVolume() removes existing stop loss and take profit
04 Nov 2024, 11:48


Hi!

I have a manually placed a pending order in cTrader with a stop loss and take profit.

My cBot iterates pending orders and updates their volume in order to reflect a propotional risk of my balance, for example 1%,

However I have noticed that whenever I call PendingOrder.ModifyVolume() which successfully updates the volume, then my stop loss and take profit is gone.

foreach (var order in PendingOrders)
{
   if (order.StopLoss.HasValue)
   {
       var preferredVolume = GetPreferredVolume(order); // method that calculates my preferred position size (volume)
       var currentVolume = order.VolumeInUnits;
       if (currentVolume != preferredVolume)
       {
           order.ModifyVolume(preferredVolume);
       }
   }
}

 

That results in the following log:


 

Looking in the log it looks that it calls ModifyPendingOrder under the hood with stop loss and take profit both being null.

How can order.ModifyVolume() affect the stop loss and take profit?

Thanks!


@erik.lindblad