Order Send Error 138 (Requote)

 

Hey,

I am new to MQL (thats why my EA is so simple) and I'm getting this error but I have no idea why...

The solution is probably very simple, but I just don't see it.

I think the best would be just to post my EA code, thanks for your help!

extern int MATimeframe = PERIOD_H4; 
extern int MAPeriod = 30;
bool OpenPositionBUY;
int x1;
double y1;
int x;
double y;
double Increase;
double TRStop;
int Ticket;

int init()

  {
//----
  TRStop = 0;
  Increase = 0;
  x1 = 0;
  y1 = 0;
  OpenPositionBUY = false;
  Ticket = 0;
//----
   return(0);
  }


int start()
  {
// Get MAs
 double MAx =iMA(NULL,MATimeframe,MAPeriod,0,MODE_SMA,PRICE_TYPICAL,0);
 double Price =iMA(NULL,MATimeframe,1,0,MODE_SMA,PRICE_TYPICAL,0);
 
//BUY
   if(OpenPositionBUY == false && Open[2] < MAx && Close[0] > MAx)
      {
      RefreshRates();
      OrderSend(Symbol(),OP_BUY,0.1,Ask,10,0,0,"Buy Order",123,0,Red);//Stop Loss still needed
      
      OpenPositionBUY = true;
      // Define StartValues
      x1 = Bars;  // Time
      y1 = MAx;   //Price   
       
      }
   x = Bars;
   y = MAx;
   if (y == y1) y = y + Point;
   if (x1 == x) x = x + 1;
 // Calc Trailling Stop 
   
   // Max Increase
   if ((y-y1)/(x-x1) > Increase)
      {
      Increase = (y-y1)/(x-x1);
      }
   //Drawing the Line
   TRStop = ((x-x1)*Increase + y1);
   Print ("TR Stop:  " + TRStop + " Increase:  " + Increase + " x1:  " + x1 + " x:  " + x + " y1:  " + y1 + " y:  " + y + " Price:  " + Price);
// SELL Conditions
   bool Order = OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
   if(TRStop > Price && OpenPositionBUY == true && Order == true)
   {
                  // Close Position
                  int Closed = OrderClose(Ticket,0.1,Bid,5,Blue);
                  Ticket++;
                  
                  if(Closed == true) 
                     { 
                     OpenPositionBUY = false;
                     x1 = 0;
                     y1 = 0;
                     Increase = 0;
                     TRStop = 0;
                     Ticket = 0;
                     }
                   else int Error = GetLastError(); Print("LastError = ",Error);    
   }
   
 
   
//----
   return(0);
  }
 
What is the value for Ticket ? I suspect this may be your issue . . .
 

sry,i still dont get it...

when iam buying it doesn't matter what the ticket is, right? (only when closing)

so my Ea just keeps buying and I tested with some Print() functions that my EA just comes to the OrderSend() funktion and doesn't care about the rest of the code...

 
How do you know the Error is generated by the OrderSend ? you don't seem to be checking the return value . . .
 

because when i code it like this:

int Ticket = OrderSend();

Print (Ticket);

Ticket isnt shown in the journal...

-----------------

Edit: No you seem to be right, I get nothing at all

Print("1");

OrderSend();

Print("2");

I get also nothing....

So whats the matter with this error, is it caused by the OrderClose function then?

 

If it fails you should get a -1 in the Experts tab (Journal if using the Strategy tester).

Why don't you do something like this . . .

if(OpenPositionBUY == false && Open[2] < MAx && Close[0] > MAx)
      {
      RefreshRates();
      if (OrderSend(Symbol(),OP_BUY,0.1,Ask,10,0,0,"Buy Order",123,0,Red) < 0)   //Stop Loss still needed
         {
         int GLE = GetLastError();
         Print("OrderSend failed: OP_BUY @ Ask ", Ask, " Error: ", GLE);
         }
 
Past Midnight here, night.
 

ok, its not the ordersend... :)

here its 01:30 AM, so I'll keep trying tomorrow....

thx for your help...

Reason: