Unknown ticket error

 

Hello,

I have this error in OrderModify fuction when run my code, can you help me?

Thanks




// Modifica TP per gli ordini a mercato SELL  
   
    if (OrderSelect(ticket2,SELECT_BY_TICKET)){  // verifica presenza ordine in SELL e lo seleziona 
    
      if ( EntryPointBuy > OrderTakeProfit()) {
  
        if  (OrderProfit() != 0 && OrderTakeProfit() != EntryPointBuy){                   // verifica se il profitto è diverso da 0 (se vero vuol dire che l'ordine BUY è a mercato)
     
          if (!OrderModify(ticket2,OrderOpenPrice(),OrderOpenPrice(),EntryPointBuy,OrderExpiration(),clrViolet)) {  // modifica TP ordine SELL uguale a 50% candela Bazooka BUYLIMIT
                
             stampa("Errore in OrderModify dell'ordine SELL ", GetLastError());
          }
                
        }
     }   
         
   }  
Files:
4108_error.JPG  70 kb
 
  1. You already know why, the ticket number is invalid. Probably you are trying to modify an already closed order. You never check the OrderCloseTime.
  2. I don't recommend storing ticket numbers. Use a OrderSelect loop instead, you don't need to check and have recovery handled.
    EA's must be coded to recover. If the power fails, OS crashes, terminal or chart is accidentally closed, on the next tick, any static/global ticket variables will have been lost. You will have an open order but don't know it, so the EA will never try to close it, trail SL, etc. How are you going to recover? Use a OrderSelect loop to recover, or persistent storage (GV+flush or files) of ticket numbers required.