MT5 Order List - Routing Ordes to Socket Connector and NOT getting double orders,

 

hi there all,

i recently started using this code here https://www.mql5.com/en/articles/344 to route orders out of MT5 using a socket bridge, and i wanted to route ORDERS, not DEALS, so there is no need to wait for the Orders to become Deals after execution (dont want to get slipped by the delay).

im using the server EA of the article above to route out orders that are being sent by MT.

i found that i could change the "deal" strings with "order" most of the time, like this:

void OnTrade()
  {

   // 24 hours back. 
   datetime dtStart=TimeCurrent()-60*60*24;
   // 24 hours front (in case if you live in GMT-<hours>)       
   datetime dtEnd=TimeCurrent()+60*60*24;        

    // Select history from last 24 hours.
    if(HistorySelect(dtStart,dtEnd)) 
     {
      // Go through all deals (from oldest to newest).
      for(int i=0;i<OrdersTotal();i++) 
        {
         // Get deal ticket.
         ulong ticket=OrderGetTicket(i);     

but, im getting multiple orders sent because of the delay in execution. seems like that when an order is still pending, the EA sees it as a new order and sends it again to the socket connector.

i wanted some kind of ORDER ID that is unique to a pending order / new order so that i could make the EA NOT to sent double orders, even when they are still waiting to be executed, pending.


can anyone help ?


thanks !

 

Your code is mixing history data and open orders (pending). Check the documentation please.

What you are trying to achieve is not clear, and I doubt any one will read an article to understand it.

 
angevoyageur:

Your code is mixing history data and open orders (pending). Check the documentation please.

What you are trying to achieve is not clear, and I doubt any one will read an article to understand it.

Thanks for the answer. 

What I'm trying to do is making each order generated by metatrader to be sent thru a tcp socket and not getting doubled up. 

The problem is that the EA reads the pending orders as If they were new, sending them more than one time each.  

The article just shows the socket connector that routes orders out of mt5 when they become deals, so,  I'm still changing the logic in order for the orders to be sent before they are executed (otherwise they would be deals already and I would not have to change a thing in the code). 

As the code is now,  like the part I posted above,  I'm getting doubled up / or more/ with each order,  probably because of what you said,  about me mixing things up with history and pending. 

I've read the files, help,  etc,  but I still am not able to find some string,  double, integer,  that is unique to every sent order (pending) and that I can call to filter out the multiple problem I'm having (as in sending out multiple orders thru the socket) 

Thanks again for any help you or anyone might give. 
 
gonzatti:
Thanks for the answer. 

What I'm trying to do is making each order generated by metatrader to be sent thru a tcp socket and not getting doubled up. 

The problem is that the EA reads the pending orders as If they were new, sending them more than one time each.  

The article just shows the socket connector that routes orders out of mt5 when they become deals, so,  I'm still changing the logic in order for the orders to be sent before they are executed (otherwise they would be deals already and I would not have to change a thing in the code). 

As the code is now,  like the part I posted above,  I'm getting doubled up / or more/ with each order,  probably because of what you said,  about me mixing things up with history and pending. 

I've read the files, help,  etc,  but I still am not able to find some string,  double, integer,  that is unique to every sent order (pending) and that I can call to filter out the multiple problem I'm having (as in sending out multiple orders thru the socket) 

Thanks again for any help you or anyone might give. 

The code of this article is far from optimal, but it works I suppose. So your idea to replace "deals" with "orders" seems correct (as far as I understand your goal). But you have to do it the right way.

void OnTrade()
  {

   // 24 hours back. 
   datetime dtStart=TimeCurrent()-60*60*24;
   // 24 hours front (in case if you live in GMT-<hours>)       
   datetime dtEnd=TimeCurrent()+60*60*24;        

    // Select history from last 24 hours.
    if(HistorySelect(dtStart,dtEnd)) 
     {
      // Go through all deals (from oldest to newest).
      for(int i=0;i<HistoryOrdersTotal();i++) 
        {
         // Get deal ticket.
         ulong ticket=HistoryOrderGetTicket(i);    
         
  }

You probably have to check the documentation more carefully.

 
angevoyageur:

The code of this article is far from optimal, but it works I suppose. So your idea to replace "deals" with "orders" seems correct (as far as I understand your goal). But you have to do it the right way.

You probably have to check the documentation more carefully.

thank you, angevoyageur.


i am checking the documentation more carefully,  getting the "history" part out of the code so i can try to only check orders that have been sent at the time, like "now";

ill try to print orders tickets so i can check if they are really "unique" ID's for each order, and from there on, ill try to filter out orders withn the same ID / ticket.


thanks


edit: if you can be of further help, do you think it'd be useful for me to check for the state of the order? as in:

go thru all orders / pending (not history) , check if any of them has already been placed (ORDER_STATE_PLACED), if so, do not send it to the socket, if not, then send it. ?

OR

go thru all orders / pending (not history) , check if any of them has already been placed (ticket), if so, do not send it to the socket, if not, then send it. ?

like:

void OnTrade()
   {  
       for(int i=0;i<OrdersTotal();i++) 
        {
         // Get deal ticket.
         ulong ticket=OrderGetTicket(i);     
                 
            if(OrderGetInteger(ticket)!=i) 
            {            
             send order to socket connector
            }
         }
     }