Download MetaTrader 5

How can retrieve multiple ticket numbers

To add comments, please log in or register
Neal_Van
334
Neal_Van  

Having trouble understanding how to get ticket numbers of existing trades. Any suggestions?

Thank you...  

Keith Watford
Moderator
10617
Keith Watford  
Select the order and store OrderTicket() in variables or an array
Neal_Van
334
Neal_Van  
GumRai:
Select the order and store OrderTicket() in variables or an array

I want the EA to select the order automatically. How do I get the ticket numbers? I know how to do one ticket number but I don't know how to do all the ticket numbers.

Is there a way?

Thank you.   

Keith Watford
Moderator
10617
Keith Watford  
Loop through all the orders and store the ticket numbers in an array.
Fernando Carreiro
2949
Fernando Carreiro  
// Code Example to get Magic Numbers of All Open Orders into an array

int
   intOrdersMagicNumber[],
   intOrdersTotal = OrdersTotal();

if( ArrayResize( intOrdersMagicNumber, intOrdersTotal ) == intOrdersTotal )
{
   for( int i = intOrdersTotal - 1; i >= 0; i-- ) // Making it a habit of counting down with OrdersTotal()
   {
      if( OrderSelect( i, SELECT_BY_POS, MODE_TRADES ) )
         intOrdersMagicNumber[ i ] = OrderMagicNumber();
      else
         intOrdersMagicNumber[ i ] = EMPTY;
   }
}

 

Coder's are Engineers and like all Engineers you have to do your Research (reading documentation, tutorials and looking at other's code of which there are many examples in the Code Base section).

Then after the Research, comes the Creativity and Experimentation (taking what you learn and trying to applying it).

So, before posting a question on the Forum, try to first get basic understanding and experimenting with what you learn, so that when you do post here, you have your own coding attempt as a starting point.

To add comments, please log in or register