[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 6

 
DhP:


Recalculate with each tick the number of pending orders.

If there are fewer of them, it means that one pending order has become a market order.

All remaining ones (which have become unnecessary) can be deleted.


At the time of deletion, both orders are market orders. But even if the last pending order is deleted or triggered, its ticket is still triggered and generates an error. And the penultimate one is still pending.
 
Andreev:

Thanks for the link!!! Will look into it :) With time, as well as magic number and by order type (bylimit or selllimit) is a good idea. But you probably didn't quite understand me. My problem is not marking the order, but HOW TO REMOVE IT. I am only able to delete the last pending order no matter how I define the penultimate one.
// ------------------------------------------------Ищете Ваши отложенники---------------------------------

   int orderType;
   for (int orderIndex = (OrdersTotal() - 1); orderIndex >= 0; orderIndex--)
   {
      if (!OrderSelect(orderIndex, SELECT_BY_POS))
      {
         continue;
      }

      if ((OrderSymbol() != Symbol()) || (OrderMagicNumber() != MagicNumber))
      {
         continue;
      }

      orderType = OrderType();
      if ((orderType == OP_BUY) || (orderType == OP_SELL))
      {
         continue;
      }
          ticket = OrderTicket( );                         // Номер ордера
          orderLots = OrderLots();                         // Lots   
          
          
          SL =  OrderStopLoss();                           // Значение StopLoss ордера
          TP = OrderTakeProfit();                          // Значение TakeProfit ордера
          
          
             if (ticket>0)                                               // 
                    {
                             while(OrderSelect(ticket,SELECT_BY_TICKET)==false)       // Если ордер выбран
                                 {
                                   Sleep(100);
                                 }
                                  
      
                             OrderDelete(ticket,CLR_NONE); // и удаляете их                       
                     
                            
                    }

       
      return (0);
   }
As I understood from your first post "I use the following example to define, but it closes only the last pending order instead of the first one, although all conditions are fulfilled for the first pending order. Help me find error!!!!!!!!!!!!!" - you need to delete all remaining pending orders, after turning some of them into market orders - this code should be written in your trading conditions and go ahead...
 
Roman.:
As I understood from your first post "I use the following example for definition, but it closes only the last pending order instead of the first one, though all conditions are fulfilled for the first pending order. Help me find error!!!!!!!!!!!!!" - you need to delete all remaining pending orders, after turning some of them into market orders - this code should be entered into your trading conditions and go ahead...

Thanks!!! Did not expect it to be so complicated :)))
 
Roman.:
As I understood from your first post "I use the following example for definition, but it closes only the last pending order instead of the first one, though all conditions are fulfilled for the first pending order. Help me find error!!!!!!!!!!!!!" - you need to delete all remaining pending orders, after turning some of them into market orders - this code should be entered into your trading conditions and go ahead...

Thought it might take a couple of lines ... :)
 
Andreev:

At the moment of deletion, both orders are marketable. But even if the last pending order is deleted or triggers, the ticket that triggered it will still show an error. The penultimate one will still be there.


I can't even imagine how this is possible.

If after recalculating the pending orders the Expert Advisor fails to find one order, it immediately issues a command to delete the rest.

The operation of deleting the pending orders not needed must necessarily precede (precede) any opening operation.

 
Roman.:

As I understood from your first post "I use the following example for definition, but it closes only the last pending order instead of the first one, though all conditions are fulfilled for the first pending order. Help me find error!!!!!!!!!!!!!" - you need to delete all remaining pending orders, after turning some of them into market orders - this code should be written in your trading conditions and go ahead...

// ------------------------------------------------Ищете Ваши отложенники---------------------------------

   int orderType;
   for (int orderIndex = (OrdersTotal() - 1); orderIndex >= 0; orderIndex--)
   {
      if (!OrderSelect(orderIndex, SELECT_BY_POS))
      {
         continue;
      }

      if ((OrderSymbol() != Symbol()) || (OrderMagicNumber() != MagicNumber))
      {
         continue;
      }

      orderType = OrderType();
      if ((orderType == OP_BUY) || (orderType == OP_SELL))
      {
         continue;
      }
          ticket = OrderTicket( );                         // Номер ордера
          orderLots = OrderLots();                         // Lots   
          
          
          SL =  OrderStopLoss();                           // Значение StopLoss ордера
          TP = OrderTakeProfit();                          // Значение TakeProfit ордера
          
          
             if (ticket>0)                                               // 
                    {
                             while(OrderSelect(ticket,SELECT_BY_TICKET)==false)       // Если ордер выбран
                                 {
                                   Sleep(100);
                                 }
                                  
      
                             OrderDelete(ticket,CLR_NONE); // и удаляете их                       
                     
                            
                    }

       
      return (0);
   }
Have you ever tried to write codes compactly?

Here is your code:

// ------------------------------------------------Ищете Ваши отложенники---------------------------------

   int orderType;
   for (int orderIndex = (OrdersTotal() - 1); orderIndex >= 0; orderIndex--) {
      if (!OrderSelect(orderIndex, SELECT_BY_POS))                            continue;
      if ((OrderSymbol() != Symbol()) || (OrderMagicNumber() != MagicNumber)) continue;
      orderType = OrderType();
      if ((orderType == OP_BUY) || (orderType == OP_SELL))                    continue;
      ticket = OrderTicket( );                         // Номер ордера
      orderLots = OrderLots();                         // Lots   
      SL =  OrderStopLoss();                           // Значение StopLoss ордера
      TP = OrderTakeProfit();                          // Значение TakeProfit ордера
      if (ticket>0) {
         while(OrderSelect(ticket,SELECT_BY_TICKET)==false)       // Если ордер выбран
            Sleep(100);
            OrderDelete(ticket,CLR_NONE); // и удаляете их                       
         }
      return (0);
      }
 
Andreev:

Thought it might be possible to fit in a couple of lines ... :)

Well. artmedia70 (24.07.2011 20:01) has packed everything into almost two lines. Just as you wanted)))
 

Please help me, where am I making a mistake? The idea is that on the bar where the order was closed, the order should not open


OrderSelect(OrdersHistoryTotal()-1, SELECT_BY_POS, MODE_HISTORY);
if ((условие 1)&&(условие 2)&&(OrderCloseTime()!=Time[0]))
 {
 OrderSend...; 
 }

But in the tester, after the order is closed, the conditions are still fulfilled and 1 more order is opened in the same direction

 
artmedia70:
Have you never tried writing codes compactly?

Here is your own code:

I have... :-))) It's a habit from Pascal... Readability is worse... Especially for those who aren't too "initiated"... :-))) And you need indentation in operations in nested loops and conditions to the tab width or 3 spaces - as a last resort... :-))
 
LazarevDenis:

Please help me, where am I making a mistake? The idea is that on the bar where the order was closed, the order should not open


But in the tester, after the order is closed, the conditions are still fulfilled and 1 more order is opened in the same direction


To help, google this and search for something like: open and close one order on one bar site:mql4.com - and you will be in luck.
Reason: