ERR_INVALID_TICKET

 

Hello,

I'm trying to do simple EA for the moment and i don't understand why the following one doesn't work to close all the positions :



for (int iCompteur = OrdersTotal() - 1; iCompteur >= 0; iCompteur--) // Boucle pour vérifier toutes les positions ouvertes ou en attentes
{
iTicket = OrderSelect (iCompteur, SELECT_BY_POS); // Sélection de chaque position une par une
bool Closed = OrderClose (iTicket, OrderLots(), MarketInfo (Symbol(), MODE_BID), 1, Red);
if (Closed == false)
{
int ErrorCode = GetLastError ();

string ErrAlert = StringConcatenate ("argMode - error: ", ErrorCode, ": ");
Alert (ErrAlert);
string ErrLog = StringConcatenate ("Ticket:", MarketInfo (Symbol(), MODE_ASK));
Print(ErrLog);

}}


it says ERR_INVALID_TICKET. Can anyone tells me why please?



 

  1. For large amounts of code, attach it
  2. RFTM OrderSelect does NOT return a ticket number.
    Ticket = OrderSelect (iCompteur, SELECT_BY_POS);

 
Ok, but now it tells me ERR_INVALID_FUNCTION_PARAMVALUE. Any idea ?


int start()
{
for (int iCompteur = OrdersTotal()-1; iCompteur >= 0; iCompteur--) // Boucle pour vérifier toutes les positions ouvertes ou en attentes
    {
     bool Closed = OrderClose (OrderTicket(), OrderLots(), Bid, 1, Red);
     if (Closed == false)
        {
         int ErrorCode = GetLastError ();
         string ErrAlert = StringConcatenate ("argMode - error: ", ErrorCode, ": ");
         Alert (ErrAlert);
         string ErrLog = StringConcatenate ("Ticket:" , MarketInfo (Symbol(), MODE_ASK)); 
         Print(ErrLog); 
        }
    }
return(0);
}

	          
 
a little mistake with
 string ErrLog = StringConcatenate ("Ticket:" , MarketInfo (Symbol(), MODE_ASK)); 
but it's not important with my problem. I would like to add i took a short order, that's why for the price I wrote Bid.
 
If you are going to use OrderTicket(), OrderLots(), etc you need to select the order that they apply to first . . . read the documentation, from OrderTicket() " Note: The order must be previously selected by the OrderSelect() function. "
 
nikky:
a little mistake with but it's not important with my problem. I would like to add i took a short order, that's why for the price I wrote Bid.
Once you have selected your order using OrderSelect() you can use OrderClosePrice() as the close price, then you don't need different code for Buys and Sells . . .
Reason: