Duplicate Orders

Created at 19 Sep 2015, 18:03
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!
CL

clark

Joined 24.08.2014

Duplicate Orders
19 Sep 2015, 18:03


I'm trying to cancel orders which duplicate positions using the following code but its not working.  Any suggestions would be appreciated.

            for (int i = Positions.Count - 1; i >= 0; i--)
            {
                position = Positions[i];

                var PositionLabel = position.Label;

                var PositionVolume = position.Volume;

                foreach (var order in PendingOrders)  // Loop is intended to find orders which duplicate positions and cancel them
                {
                    if ((order.Label == PositionLabel) && (order.Volume == PositionVolume))
                    {
                        CancelPendingOrder(order);
                    }
                }

 

 


@clark
Replies

ClickAlgo
19 Sep 2015, 20:59

So what you are doing is:

  • For each OpenPosition
    • For each PendingOrder
      • ​IF OpenPosition = PendingOrder Where the Label and the Volume are the same
        • ​CancelPendingOrder

The Pseudocode above shows that you will close all orders where a position exists with the same label name and the same volume amount.

You are missing a curly brace at the end of your code and you could have written your iterations like this:

foreach(var position in Positions)
{
      foreach(var order in PendingOrders)
      {
             if(order.label == position.Label && order.Volume == position.Volume)
             {

              }
      }
}

I am sure you can work the rest out. :-)


@ClickAlgo