cancel pending orders by label

Created at 19 May 2021, 14:45
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!
KR

krystek128@wp.pl

Joined 20.05.2019

cancel pending orders by label
19 May 2021, 14:45


hello everyone.
I am trying make bot. 
and I have not idea how to cancel pending order by label.  roughly my robot making pending orders in bouth direction i am looking for cancel sell pending orders when 1st buy is open and cancel buy pending orders when 1st sell is open. 

I am just learning programing: 

try this;

public void openedposition(PositionOpenedEventArgs args)
        {
            var pos = args.Position;

            foreach (var order in PendingOrders)
            {
                if (pos.Label != order.Label)

                    // CancelPendingOrder(order);


                    if (pos.Label == label1)
                    {


                        Chart.RemoveObject("g1");
                        Chart.RemoveObject("g2");
                        Chart.RemoveObject("g3");
                        Chart.RemoveObject("g4");
                        Chart.RemoveObject("g5");
                        Chart.RemoveObject("g6");
                        Chart.RemoveObject("g7");
                        Chart.RemoveObject("g8");


                    }
                    else
                    {

                        Chart.RemoveObject("r1");
                        Chart.RemoveObject("r2");
                        Chart.RemoveObject("r3");
                        Chart.RemoveObject("r4");
                        Chart.RemoveObject("r5");
                        Chart.RemoveObject("r6");
                        Chart.RemoveObject("r7");
                        Chart.RemoveObject("r8");

                    }
                CancelPendingOrderAsync(order);

            }


@krystek128@wp.pl