Select order tickets individually

 

Hello everyone,

I am trying to modify pending orders with order tickets, The problem is that if I attach the EA on 2 or more different charts order tickets are mixed and this is a problem, can someone help me? below is the complete code of the logic.

//---4 Count total orders placed by the EA on current Symbol

   string orderSymbol_;
   int ordersTotal = OrdersTotal();
   int expertOrders = 0;
   long orderMagicEXT;
   ulong orderTicket;
   for(int i = 0; i < ordersTotal; i++)
     {
      orderTicket = OrderGetTicket(i);              // Get Order Ticket
      if(!OrderSelect(orderTicket))
        {
         Print("There is an error on OrderSelect Function: " + (string)GetLastError());
        }                       // Select ticket
      long orderMagic = OrderGetInteger(ORDER_MAGIC);     // Get Order Magic Number
      orderMagicEXT = orderMagic;
      orderSymbol_ = OrderGetString(ORDER_SYMBOL);
      //-- Add Symbol filter too
      if(orderMagic == I_magicNumber && Symbol() == orderSymbol_)
        {
         expertOrders++;

        }
     }

//---4---------------------------------------------

    ulong ordTKT;

// Place Sell stop pending order------------------

   if(priceRangeUp == true && priceRange >= triggerPriceRange && spreadOK == true && totalTrades < maxTrades && fundsOK == true && tradeAllowed == true)
     {

      SELL_Stop(price_sell,SL_sell,TP_sell, volume);

      Comment("SELL OK");
      ordTKT = OrderGetInteger(ORDER_TICKET);
     }
//---
//---END SELL_STOP
//---

//---BUY STOP
//---


// Place Buy stop pending order------------------

   if(priceRangeUp == false && priceRange >= triggerPriceRange && spreadOK == true && totalTrades < maxTrades && fundsOK == true && tradeAllowed == true)
     {

      BUY_Stop(price_buy,SL_buy,TP_buy, volume);

      Comment("BUY OK");
      ordTKT = OrderGetInteger(ORDER_TICKET);
     }

//---
//---END BUY STOP 



//--- Modify SELL Stop


   if(expertOrders > 0)
     {
      if(orderSymbol_ == Symbol())
        {
         if(orderMagicEXT == I_magicNumber)
           {
            if(OrderGetInteger(ORDER_TYPE) == ORDER_TYPE_SELL_STOP)
              {
               if(bid > oldBid_sell + (1 * _Point))
                 {

                  modifySellStop(price_sell,SL_sell,TP_sell,volume,ordTKT);

                  oldBid_sell = bid;
                 }
              }
           }
        }
     }

//---

//--- Modify BUY STOP
   if(expertOrders > 0)
     {
      if(orderSymbol_ == Symbol())
        {
         if(orderMagicEXT == I_magicNumber)
           {

            if(ask < oldask_buy - (1 * _Point))
              {

               if(OrderGetInteger(ORDER_TYPE) == ORDER_TYPE_BUY_STOP)
                 {

                  modifyBuyStop(price_buy,SL_buy,TP_buy,volume,ordTKT);
                  oldask_buy = ask;
                 }
              }

           }
        }

     }