Is this how I do orderselects with magic number?

 

OrderSelect(16384, SELECT_BY_TICKET);


if not, how do i find out the ticket number in mql4 code?

 
trader346:

OrderSelect(16384, SELECT_BY_TICKET);


if not, how do i find out the ticket number in mql4 code?

ticket number is returned in two ways:

1. from a new order

ticket = OrderSend(. . .);


2. from an existing order

ticket = OrderTicket(. . .);


the order must be previously selected by OrderSelect(. . .)


use OrdersTotal(. . .) or OrdersHistoryTotal(. . .) to find all orders in trading or history

then go through and use OrderSelect(index, SELECT_BY_POS, MODE_TRADES) to select one


btw, the magic number is used by you own meaning

 
E06 wrote >>

ticket number is returned in two ways:

1. from a new order

ticket = OrderSend(. . .);

2. from an existing order

ticket = OrderTicket(. . .);

the order must be previously selected by OrderSelect(. . .)

use OrdersTotal(. . .) or OrdersHistoryTotal(. . .) to find all orders in trading or history

then go through and use OrderSelect(index, SELECT_BY_POS, MODE_TRADES) to select one

btw, the magic number is used by you own meaning

Hi E06

I need to get clear on this, if I already have the ticket number, do I have to loop through all the orders anyway?

In other words if I have the ticket number OrderSelect(16384, SELECT_BY_TICKET); is all I need in this case, no need to loop through all orders.

Thanks

Keith

 
kminler wrote >>

Hi E06

I need to get clear on this, if I already have the ticket number, do I have to loop through all the orders anyway?

In other words if I have the ticket number OrderSelect(16384, SELECT_BY_TICKET); is all I need in this case, no need to loop through all orders.

Thanks

Keith

Yes, if you have the ticket number OrderSelect(ticket, SELECT_BY_TICKET) will select the target order.

It returns TRUE if the function succeeds. It returns FALSE if the function fails. To get the error information, one has to call the GetLastError() function.

 
trader346:

OrderSelect(16384, SELECT_BY_TICKET);


if not, how do i find out the ticket number in mql4 code?

Below is how you select an order with your magicnumber. Basically setup a loop with the number of open trades, loop through each trade, and if the trade has a magicnumber=16384, then do something else.


int openorders=OrdersTotal();
    for(int OR=0;OR<openorders;OR++)
       {
         OrderSelect(OR,SELECT_BY_POS,MODE_TRADES);
         if(OrderMagicNumber()==16384)
           {if(Orderticket()==yourticketnumber){'do something'}} // exit
  
       }
 
c0d3:

Below is how you select an order with your magicnumber. [...]

For completeness - the method obviously changes if your order is closed. In which case you need to loop through using OrdersHistoryTotal() and MODE_HISTORY rather than OrdersTotal() and MODE_TRADES. And all this is irrelevant if you already know the ticket number; you just use OrderSelect().

Reason: