Alert: MT4 Terminal Duplicating Orders Sent by Experts - page 5

 

Hi Friends:

I'm sorry I didn't answer before: I was unaware of your posts because I received no notification from Metaquotes. I indeed opened a ticked, as RaptorUK recommended, but they never answered it at all. I do the same as JamesMadden when neccessary: I just close the order and loose the spread. If it's not that risky, I just leave it there! (if my EA is profitable, it will win more than loose in the long run) However, of course I don't like the bug.

Now I am having new problems with build 600 and I'd like to know, if someone knows, how do you get them to answer? :)

PD: How do I get this web application to send me an email when this post gets updated? I am already subscribed to the topic.

 
Ricardo1:

Hi Friends:

I'm sorry I didn't answer before: I was unaware of your posts because I received no notification from Metaquotes. I indeed opened a ticked, as RaptorUK recommended, but they never answered it at all. I do the same as JamesMadden when neccessary: I just close the order and loose the spread. If it's not that risky, I just leave it there! (if my EA is profitable, it will win more than loose in the long run) However, of course I don't like the bug.

Now I am having new problems with build 600 and I'd like to know, if someone knows, how do you get them to answer? :)

when you find out let me know . . . I have an open ticket from March 2013 that has never had a reply. All I can suggest is to keep adding new comments each time asking for news or a reply.


PD: How do I get this web application to send me an email when this post gets updated? I am already subscribed to the topic.

email notifications haven't worked for a few years . . . perhaps you could report it to the Service Desk
 
RaptorUK:
when you find out let me know . . . I have an open ticket from March 2013 that has never had a reply. All I can suggest is to keep adding new comments each time asking for news or a reply.

email notifications haven't worked for a few years . . . perhaps you could report it to the Service Desk



Hi,

I just found this topic because I went searching for exactly this problem. I haven't noticed the problem before but it happened for me today.

Regardless of the experts log, which like mentioned earlier does record trades, there is the MetaTrader journal which records all trades made, by EA or by person. Today I found a trade in my portfolio that was a duplicate of a trade placed only seconds earlier but the second trade did not appear in the experts log or the MetaTrader journal.

I've asked my broker to compare their logs of incoming requests with trades executed but I suspect they either do not keep logs or will not want to investigate.

If the EA did place 2 orders I would expect to see both in the journal. Even if the desktop application for some reason duplicated the request I would expect the server to respond and record the second trade. It appears more that the trade is being executed from the server and not the client.

This is the first time I've noticed the problem and I can't find any way to reproduce the issue. The amounts I'm working with now are very small so the value isn't important but it does raise concern over the viability of MetaTrader.

Just thought I'd lend my thoughts to a topic that's been hanging around for a while.

Edit:

I've been checking further and found another instance. The order had already been closed by stop loss so I didn't notice it. In both cases the EA placed an expected order. That shows in the journal immediately followed by a login message which corresponds with the phantom order being placed.

If anyone else thinks a phantom order has occurred please check for the login message in the journal. It may be significant.

 

Seems like I'm not the only one affected by this annoying problem. Same as spikedog, my EA requested for a market order that resulted in another duplicated entry of the same lotsize within millisecs, duplicate order log was shown in Journal but not Experts tab; I've since modified my codes slightly to hopefully better guard against this problem by filtering double trade within the same bar (trading on bar open only) right before OrderSend().

It's the first time I had this duplicate trade problem; had opened more than 500 trades with 3 brokers since & no problem until now. Btw, the subsequent trades works fine again.

As attached is my code to process OrderSend() when the duplicate problem happens. I can't see how my EA is the cause for the duplicate order. Only possible reason I can think of right now is perhaps on a very rare occasion, the server was processing my OrderSend but returns "-1" somehow & my EA proceeds to make another request treating the 1st as a requote. Just my mere speculation.


            bool Buy_Ticket = false;
            while(Buy_Ticket==false){     //Loop to solve Requote issues
               for(int BT_count=0; BT_count < RequoteTries; BT_count++){
                  if (!IsTradeAllowed()) Sleep(RequoteTries_WaitingTime);
                  RefreshRates();

                  int B_Spread = MarketInfo(Symbol(), MODE_SPREAD);  //TO CAPTURE EXACT SPREAD UPON BUY ORDER FOR SL
                  Buy_Ticket = OrderSend(Symbol(),0,order_lotsize,Ask,Slippage,0,0,EntryCode_comment,Magic,0,Blue) > 0;

               
                  if (Buy_Ticket==true){     //Modify to give SL & TP if new buy order executed
                     for(int buyMod=0; buyMod < OrdersTotal(); buyMod++){
                        if (OrderSelect(buyMod,SELECT_BY_POS,MODE_TRADES)){
                           if ((OrderSymbol()!=Symbol()) || (OrderType()!=OP_BUY)) continue;
                           if ((OrderStopLoss()==0) && (OrderTakeProfit()==0)){
                              double B_SL = NormalizeDouble((OrderOpenPrice()-((B_Spread*Point)+stoploss)),Digits);
                              double B_TP = NormalizeDouble((OrderOpenPrice()+takeprofit),Digits);

                              bool buy_ModSL_succeed = false;
                              while(buy_ModSL_succeed==false){     //Loop to solve SL+TP modify Requote issues   
                                 for(int buyMod_count=0; buyMod_count < RequoteTries; buyMod_count++){
                                    if (!IsTradeAllowed()) Sleep(5000);
                                    RefreshRates();                                 
                                    if (OrderModify(OrderTicket(), OrderOpenPrice(), B_SL, B_TP, 0, Red)==false) continue;
                                    buy_ModSL_succeed = true;
                                    Print(entrycode_txt," initiated Long trade successfully modified SL & TP.");
                                    break;                        
                                 }  //End FOR loop for requote handling
                                 if (buy_ModSL_succeed == false){
                                    getError = GetLastError();
                                    Alert("Error: ",getError," in Buy order#:",OrderTicket()," modify for SL:",B_SL," & TP:",B_TP," after ",RequoteTries," attempts.");
                                    break;
                                 }
                              }  //End WHILE loop for SL+TP modify requote handling
                           }  //End IF statement to select new orders without SL & TP
                        }  //End IF orderselect
                     }  //End FOR loop to modify new orders without SL & TP 
                  }  //End IF statement when buy order accepted & need SL+TP modify

                  if (Buy_Ticket==false) continue;
                  else break;
               }  //----------------------------//End FOR loop to carry out ordersend for buy trade when requote
               if (Buy_Ticket==false) break;    //Exit WHILE loop to handle Requote issues, fail to buy
            }  //-------------------------------//End WHILE loop to solve Requote issues
 
BigFisherman:

I can't see how my EA is the cause for the duplicate order.

It might be connected with this error in your code, you should fix it and test again . . .

                  Buy_Ticket = OrderSend(Symbol(),0,order_lotsize,Ask,Slippage,0,0,EntryCode_comment,Magic,0,Blue) > 0;

               
                  if (Buy_Ticket==true){     //Modify to give SL & TP if new buy order executed

OrderSend() returns an int not a bool so checking if the return value is "true" is incorrect.

 

@BigFisherman

B.T.W what's going on with yor code ?

if (Buy_Ticket==true){     //Modify to give SL & TP if new buy order executed
if (Buy_Ticket==false) continue;

and again ?

else break;
 
RaptorUK:

It might be connected with this error in your code, you should fix it and test again . . .

OrderSend() returns an int not a bool so checking if the return value is "true" is incorrect.


Thanks raptoruk for the suggestion. You are right :)
 
BigFisherman:

Thanks raptoruk for the suggestion. I'm aware of that. However I don't think that's the cause for the duplicate trade because the code presented is valid, though little confusing.
How is the code valid ? if the OrderSend() works you get a value greater than 0 returned, i.e the ticket number, if it fails you get -1 returned, you are testing for true or false . . . fix your code and remove the uncertainty.
 
RaptorUK:
How is the code valid ? if the OrderSend() works you get a value greater than 0 returned, i.e the ticket number, if it fails you get -1 you are testing for true or false . . . fix your code and remove the uncertainty.



Thanks again.

Cheers!

 
RaptorUK:
How is the code valid ? if the OrderSend() works you get a value greater than 0 returned, i.e the ticket number, if it fails you get -1 returned, you are testing for true or false . . . fix your code and remove the uncertainty.


Hi RaptorUK,



I've a question not exactly regarding the topic of this thread but hoping to use my previous post as an example to deepen my understanding of mql4 coding & perhaps may also help other beginners like myself (if u think it's off-topic & needs a new thread, please delete this & let me know).

I was slightly confused at first about my initial way of declaring Buy_Ticket as bool rather than int, so I did further tests on it. While I agree my original way of reading OrderSend() as bool is not a good way of coding (confusing), but my test shows it's valid. To make it simpler for reading, I've coded the following, please advice & thanks for your time.


P.S.: As advised, I've already modified my EA to read OrderSend() as int.



//+------------------------------------------------------------------+
//|                                                    Test_Bool.mq4 |
//|                                     Copyright 2014, BigFisherman |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, BigFisherman"

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//---
   
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
int start()
{
//---
   
   for (int SimRun=0; SimRun<3; SimRun++){
      bool Buy_Ticket = 0;
      int Ordersend = 0;            //AS AN EXAMPLE TO SIMULATE OrderSend() RETURNED CODE

      switch (SimRun)
      {
         case 0: break;             //FOR Ordersend==0
         case 1:
         {
            Ordersend = 1;          //SIMULATE SUCCESSFUL ORDERSEND() RETURNING TICKET NO. > 0
            break;
         }
         case 2:
         {
            Ordersend = -1;         //SIMULATE FAILED ORDERSEND() RETURNING "-1"
            break;
         }
      }
      
      
      // (MY ORIGINAL WAY OF CODING)   Buy_Ticket = OrderSend(Symbol(),0,order_lotsize,Ask,Slippage,0,0,EntryCode_comment,Magic,0,Blue) > 0;
      Buy_Ticket = Ordersend > 0;   //SIMPLIFIED CODE FOR EASIER READING
      
      
      if (Buy_Ticket==true){
         Print("** Buy_Ticket returns true  **  SimRun: "+SimRun+"  Ordersend: "+Ordersend+"  Buy_Ticket: "+Buy_Ticket);
      }
      else{                         //if (Buy_Ticket==false)
         Print("** Buy_Ticket returns false **  SimRun: "+SimRun+"  Ordersend: "+Ordersend+"  Buy_Ticket: "+Buy_Ticket);
      }
   }
   return(0);
}
//+------------------------------------------------------------------+


Journal

2014.03.30 12:57:31.223 2014.03.25 23:30  Test_Bool AUDJPY,M30: ** Buy_Ticket returns false **  SimRun: 0  Ordersend: 0  Buy_Ticket: 0
2014.03.30 12:57:31.223 2014.03.25 23:30  Test_Bool AUDJPY,M30: ** Buy_Ticket returns true  **  SimRun: 1  Ordersend: 1  Buy_Ticket: 1
2014.03.30 12:57:31.223 2014.03.25 23:30  Test_Bool AUDJPY,M30: ** Buy_Ticket returns false **  SimRun: 2  Ordersend: -1  Buy_Ticket: 0
Reason: