OrderSend function returns 0 and no position is opened

 

Hi,

since a few days (the last update) I have noticed a problem with my Expert: OrderSend function 0 and no position is opened. There is no error returned but no ticket is created. Here is my code:

 RefreshRates();
         if (pOrderType==OP_BUY)
         {
            result=OrderSend(pSymbol, pOrderType, pLots, Ask, 0, /*Ask-NormalizeDouble(pSL*SymPoints,SymDigits)*/ 0, Ask+NormalizeDouble(pTP*SymPoints,SymDigits));
         }
         else
         {
            result=OrderSend(pSymbol, pOrderType, pLots, Bid, 0, /*Bid+NormalizeDouble(pSL*SymPoints,SymDigits)*/ 0, Bid-NormalizeDouble(pTP*SymPoints,SymDigits));
         }
     }

.

In another version of this Expert I am also checking it the Trading Context is free (even though I do not get any error suggesting it) and it is.

What can be the reason? I am really getting frustrated...


Best regards

Huckey

 
So you check that result is > 0 and the print the last error ? and what do you get ? can you copy and paste the log entry please. Perhaps you Broker became an ECN Broker ?
 
RaptorUK:
So you check that result is > 0 and the print the last error ? and what do you get ? can you copy and paste the log entry please. Perhaps you Broker became an ECN Broker ?


Here is the result of:

   if (result<=0)
   {
      Print("Last Error: ", GetLastError());
   };

2012.03.01 00:23:49 MyGreatStrategy EURUSD,H4: Last Error: 0.

I am on a test account created from within MetaTrader 4. I get this phenomenon both on MetaQuotes and Forex.com test accounts :-(

Any clues? :-)

Best regards

Huckey

 
huckey:


Any clues? :-)

What other code do you have between the 2 bits of code that you posted ?

Try something like this instead . . .

 RefreshRates();
         if (pOrderType==OP_BUY)
         {
            result=OrderSend(pSymbol, pOrderType, pLots, Ask, 0, /*Ask-NormalizeDouble(pSL*SymPoints,SymDigits)*/ 0, Ask+NormalizeDouble(pTP*SymPoints,SymDigits));
            if (result < 0) Print("Buy order failed: ", GetLastError());
            else Print("Buy order placed, ticket: ", result);
         }
         else
         {
            result=OrderSend(pSymbol, pOrderType, pLots, Bid, 0, /*Bid+NormalizeDouble(pSL*SymPoints,SymDigits)*/ 0, Bid-NormalizeDouble(pTP*SymPoints,SymDigits));
            if (result < 0) Print("Sell order failed: ", GetLastError());
            else Print("Sell order placed, ticket: ", result);

         }
     }
 
I had nearly the same issue with forex.com except that I get error 133 - Trade is disabled. After contact with the broker they explained me that EAs can work only at sufixed currency pairs which are initially hidden. You can contact your broker.
 
huckey:
2012.03.01 00:23:49 MyGreatStrategy EURUSD,H4: Last Error: 0.
  1. That means no error. You most likely didn't even call OrderSend
  2. Only call getLastError after you get error return, like Raptor showed.
  3. OrderSend returns -1 on error (zero may be a valid ticket)
  4. Post ALL the code from after the decision through the alerts.
  5. On ECN brokers you must open first and THEN set stops
  6. Drop your NormalizeDouble. That call is ALWAYS unnecessary - don't use it.
 

Hi again,

just wanted to thank for all replies - they led me to the solution.

Eventually, the code proposed by Raptor did not change the situation - I still got 0. I started playing around and come to the conclusion that there was a problem with Take Profit parameter in my code. The strange thing is that I did not get INVALID_STOPS error but 0 and that the code had worked before and stop working without any change to it (and was working on a test account).

So the case is closed and the error showed to be invalid Take Profit.

Best regards

Jacek

Reason: