OrderSend error #138

 

Hello,

in backtest i get this order error 138.

 

This is my code.

  RefreshRates();
      MqlTick tick;
      if(SymbolInfoTick(_Symbol,tick) == true)
      {
         double xbid = tick.bid;
         double xask = tick.ask;
         double point=SymbolInfoDouble(_Symbol,SYMBOL_POINT);
        
         int operation=OP_BUY;
         double price=xask;
         double target=price + 100  * point;
         double stop=price - 100  * point;
         double lots=0.01;
         int ticket=OrderSend( _Symbol,operation,lots,price,50,stop,target,"",0,0,clrRed);
         if(ticket <= 0)
         {
            PrintFormat("FAILED %s %.2f price=%.8f stop=%.8f target=%.8f",(operation == OP_SELL ? "SELL" : "BUY"),lots,price,stop,target);                    
         }
         else
            Print("HURRA");
      }
      else
      {
        
         Print("#ERROR SymbolInfoTick");
      }

 

 

 

 

What is wrong ? Thank you. 

 
chinaski:

Hello,

in backtest i get this order error 138.

What is wrong ? Thank you. 

Print your error code when ticket <= 0

if(ticket <= 0)
{
   PrintFormat("FAILED %s %.2f price=%.8f stop=%.8f target=%.8f ERROR:%i",(operation == OP_SELL ? "SELL" : "BUY"),lots,price,stop,target,GetLastError());                    
}

Your 138 might be arising somewhere else.

----

[ Moved to MQL4 section ]

 
honest_knave:

Print your error code when ticket <= 0

if(ticket <= 0)
{
   PrintFormat("FAILED %s %.2f price=%.8f stop=%.8f target=%.8f ERROR:%i",(operation == OP_SELL ? "SELL" : "BUY"),lots,price,stop,target,GetLastError());                    
}

Your 138 might be arising somewhere else.

----

[ Moved to MQL4 section ]

Hello,

how do you mean, please ? The order has not been placed. 

What is the secret to get information why it has not been placed.

Do you know the secret undocumented hidden path that could save my time in order to get something run that simply should run ?

Thank you 

 
chinaski:

Hello,

how do you mean, please ? The order has not been placed. 

What is the secret to get information why it has not been placed.

Do you know the secret undocumented hidden path that could save my time in order to get something run that simply should run ?

Thank you 

From the OrderSend() documentation:

Returned value

Returns number of the ticket assigned to the order by the trade server or -1 if it fails. To get additional error information, one has to call the GetLastError() function.

 So, you attempt to send the order.

If you get -1, the OrderSend() failed. Checking GetLastError() will tell you why it failed.

PS I've never actually seen a ticket #0, but in theory it could happen. Your code should read:

// if(ticket <= 0)
if(ticket < 0)


 

OrderSend - Trade Functions - MQL4 Reference
OrderSend - Trade Functions - MQL4 Reference
  • docs.mql4.com
OrderSend - Trade Functions - MQL4 Reference
 
chinaski:

Hello,

how do you mean, please ? The order has not been placed. 

What is the secret to get information why it has not been placed.

Do you know the secret undocumented hidden path that could save my time in order to get something run that simply should run ?

Thank you 

Always clear the Error state before the operation you want to check with the function "ResetLastError()":
...

ResetLastError();
int ticket = OrderSend( _Symbol, operation, lots, price, 50, stop, target, "", 0, 0, clrRed );
if(ticket <= 0)
{
   PrintFormat( "FAILED %s %.2f price=%.8f stop=%.8f target=%.8f ERROR:%i",
      (operation == OP_SELL ? "SELL" : "BUY"), lots, price, stop, target, _LastError );                    
}
else
   Print( "HURRA" );

...
Also, error 138 is a "Requote" error!
 
honest_knave:

From the OrderSend() documentation:

 So, you attempt to send the order.

If you get -1, the OrderSend() failed. Checking GetLastError() will tell you why it failed.

PS I've never actually seen a ticket #0, but in theory it could happen. Your code should read:

// if(ticket <= 0)
if(ticket < 0)


 

Please don't reply. You replies are no help, Sir.

I get error 138 ok and my question was why ? So you don't know and i ask you, do not answer because the next who has the problem

needs to read all your useless answers.

Thank you for your understanding, 

 
chinaski:

Please don't reply. You replies are no help, Sir.

I get error 138 ok and my question was why ? So you don't know and i ask you, do not answer because the next who has the problem

needs to read all your useless answers.

Thank you for your understanding, 

Good luck, you'll need it.
 
chinaski:

Please don't reply. You replies are no help, Sir.

I get error 138 ok and my question was why ? So you don't know and i ask you, do not answer because the next who has the problem

needs to read all your useless answers.

Thank you for your understanding, 

You are being totally inappropriate as @honest_knave was in fact being very helpful. If you are so ignorant and moronic to not understood that, then you don't deserve to be helped by anyone.

So, I will reiterate the same words as @honest_knave. Good luck, and I will add too, Good Riddance!
 

Ok, from Carreiro

2 usefull comments.

1. Clear error state before calling OrderSend -> ResetLastError();

2. Error #138 is a requote error

Thank you for that. 

 

So that makes sense. The #138 was triggered by calling RefreshRates().

 

My tone was my a bit aggressive, sorry for that, but i don't agree:

 

The important point here was

ResetLastErorr()

, something that honest_knave most likely had in his mind when he gave me the hint 

the error may was not related to the OrderSend.

 
chinaski: The important point here was ResetLastErorr()
Unnecessary for functions that return an error (such as OrderSend returning -1.) Only print _LastError if you have an error. Check your return codes What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles

As honest_knave said:
If you get -1, the OrderSend() failed. Checking GetLastError() will tell you why it failed. Your 138 might be arising somewhere else.
You didn't print _LastError when you had an error, so you didn't know why.
Reason: