String defining and finding order by label

Created at 21 Nov 2016, 22:43
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!
IR

iRobot

Joined 17.02.2013

String defining and finding order by label
21 Nov 2016, 22:43


Why can't I define string

"string _Long = Symbol.Code.ToString() + "Long";"

in the section where all the parameters are defined and can only do it in OnBar() or PositionsOnClosed(PositionClosedEventArgs args)?

 

Going forward with the question: now I define labels in OnBar() for orders and then I define labels in PositionsOnClosed(PositionClosedEventArgs args) to find same orders and cancel them. It seems like it is unnecessary doubling of strings. How can I find orders in PositionsOnClosed(PositionClosedEventArgs args) without defining labels once again?

 

protected override void OnBar()
        {.....

            string buy_Order = Symbol.Code.ToString() + "Buy Order";

PlaceLimitOrder(TradeType.Buy, Symbol, Volume*2, (EntryPrice - DistanceOnOrders * Symbol.PipSize) , buy_Order, StopLossInPips_buy1, TakeProfitInPips1);

       }

        private void PositionsOnClosed(PositionClosedEventArgs args)
        {
            string buy_Order = Symbol.Code.ToString() + "Buy Order";
            
            var B1 = Positions.FindAll(buy_Order, Symbol, TradeType.Buy);

            
            foreach (Position position in B1)
            {
                    Print("Canceled " + buy_Order);

                    foreach (var order in PendingOrders)
                    {     
                        if (order.Label == buy_Order)
                            CancelPendingOrder(order);
                    }        
            }


@iRobot