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

 
splxgf:

How do you determine which is which of the two?

https://book.mql4.com/ru/trading/orderclose

And filter by symbol if necessary, fully working example

https://book.mql4.com/ru/trading/ordermodify


I am using the following example to determine, but it closes only the last pending order instead of the first one, although all conditions are met for the first pending order. Help me find an error!!!!!!!!!!!!!

 if (Bid>=Openup-0.0005)
 {
 for(int count = OrdersTotal()-1; count >= 0; count--)
  {  
     OrderSelect(count, SELECT_BY_POS, MODE_TRADES);
     if (OrderType() == OP_BUYLIMIT)
       {  
        OrderDelete(ticket,CLR_NONE);
       }
  }
 }
 
Andreev:


I am using the following example to determine, but it closes only the last pending order instead of the first one, although all conditions are met for the first pending order. Help me find an error!!!!!!!!!!!!!


The easiest way to determine which order of the two to close is by the magic number. Assign them different numbers when you set them up. The example you showed above lacks this check. Also write OrderTicket() instead of ticket.
 
tol64:

The easiest way to determine which order of the two to close is by the magic number. Assign them different numbers when you set them up. The example you showed above lacks this check. Also write OrderTicket() instead of ticket.

Thanks for the reply! I have already been advised a magic number, but where to put it when defining a pending order and how to relate it to a ticket - I don't understand.
 
Andreev:

Thanks for the reply! I have already been advised to use magic number, but I do not understand where to place it when defining a pending order and how to relate it to a ticket.


magic should be set when opening an order, but we must make sure that the number of different orders is different, otherwise it will not make sense. below is a link to a full description of the OrderSend function where all variables that can be set when opening an order, it is YOU who should be interested in the magic variable, but to work correctly, all variables before it must be filled in, all variables after - as you see fit

https://docs.mql4.com/ru/trading/OrderSend

 
LazarevDenis:


magic should be set when opening an order, but make sure that the number of different orders is different, otherwise it makes no sense, below is a link to a full description of the OrderSend function where all variables that can be set when opening an order, YOU should be interested in the magic variable, but to work correctly all variables before it should be filled in, all variables after - as you see fit

https://docs.mql4.com/ru/trading/OrderSend


Why do different orders need different magic?
 

Please give me the correct code. I wrote an EA and it generates only two errors during compilation - I don't know how to get rid of them.

these errors 1) 'SL' - variable already defined C:\Program Files\MetaTrader Finam\experts\$.mq4 (43, 11)

and 2) 'TP' - variable already defined C:³ Files\MetaTrader Finam\experts\$.mq4 (45, 11)

The code of the Expert Advisor below:

 
extern int  

            Diapazon=1200,
            Slipege=500,
            TP=1500,
            SL=15000;   
            
double pa, pb, pt;
int    ls, dg;                  

  int start()                                // Спец. функция start()
  {  
   
   pa=MarketInfo(Symbol(),MODE_ASK);
   pb=MarketInfo(Symbol(),MODE_BID);
   pt=MarketInfo(Symbol(),MODE_POINT);
   dg=MarketInfo(Symbol(),MODE_DIGITS);
   ls=MarketInfo(Symbol(),MODE_STOPLEVEL);
   
   //---------------------------------------+
    
   if
   
   {
   
   double variable1 = NormalizeDouble(pa+ls*pt,dg); 
  
   double variable2 = NormalizeDouble(pb-ls*pt,dg);
   
   //---------------------------------------------+ 
  
   double pa = NormalizeDouble(Ask+Diapazon*Point,Digits);
   
   double SL = NormalizeDouble(Bid+(Diapazon-SL)*Point,Digits);
  
   double TP = NormalizeDouble(Ask+(Diapazon+TP)*Point,Digits);

 
  
   double pb = NormalizeDouble((Bid+Diapazon*Point,Digits);
  
   double SL = NormalizeDouble(Bid+(Diapazon+SL)*Point,Digits);
  
   double TP = NormalizeDouble(Bid+(Diapazon-TP)*Point,Digits);
   
   }
  
                                       // Открытие BUY
                                         
   OrderSend(Symbol(),OP_BUYSTOP, 0.05,Ask+Diapazon*Point,3,Bid+(Diapazon-SL)*Point,Ask+(Diapazon+TP)*Point);
   
                                     // Открытие SELL
   
   OrderSend(Symbol(),OP_SELLSTOP,0.05,Bid+Diapazon*Point,3,Bid+(Diapazon+SL)*Point,Bid+(Diapazon-TP)*Point);  

   return;                                   // Выход из start()
  }
  
 
Vinin:

And why different warrants need different magik?

Apparently for that - a few posts above :-))) - "The easiest way to determine which order of the two to close is by the magic number. Assign them different numbers when you set them up. The example you showed above lacks this check. Also write OrderTicket() instead of ticket".
 
tol64:

The easiest way to determine which order of the two to close is by the magic number. Assign them different numbers when you set them up. The example you showed above lacks this check. Also, write OrderTicket() instead of ticket.

Remember the time of setting orders, then compare the time in the loop and delete the oldest one.
 
Andreev:


I am using the following example to determine, but it closes only the last pending order instead of the first one, although all conditions are met for the first pending order. Help me find an error!!!!!!!!!!!!!


Don't exclude the variant of transformation of the first order into a market order, and, as consequence, impossibility of its removal by this cycle on limit orders?