Error 138 and modify order

Back to topics list To post a new topic, please log in or register
avatar
2
andy1979 2015.12.28 22:13
 

Hi guys, im new in EA, im create EA but im having trouble with errors 138, and how do i put take profit by modify order from input  because when i create modify order take profit the result still error 138, here my EA

#property copyright "Andy"
#property link      "Andy"
 
extern int     Magic = 99999;
extern double  Lots=0.01;
extern int     Step=50;
extern double  TakeProfit=50;


int cnt=0;
int pt,FO,SO;
double LotSell=0;
double LotBuy=0;
double LastPrice=0;
double OpenOrders=0;

int init()
{
  if(Digits==3||Digits==5)pt=10;
   else pt=1;
}
int deinit()
{
  Comment("");
  return(0);
}
int start()
{  

 if( LastPrice == 0 ) {
   for( cnt = 0; cnt < OrdersTotal(); cnt++ ) {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if( OrderSymbol() == Symbol() ) {
         LastPrice = OrderOpenPrice();
      }
   }
 if (MyOrdersTotal(Magic)==0)
  {
    FO=OrderSend(Symbol(),OP_BUY,Lots,Ask,3*pt,0,0,"",Magic,0,Blue);
    if(FO<0)
    {
    Print("First order error #",GetLastError());
    }
      else
    Print("First order successfully");
    
 if (MyOrdersTotal(Magic)==1)
    SO=OrderSend(Symbol(),OP_SELL,Lots,LastPrice+Step*Point*pt,3*pt,0,0,"",Magic,0,Red);
    if(SO<0)
    {
    Print("Second order error #",GetLastError());
    }
      else
    Print("Second order successfully");
  }
} 
}
int MyOrdersTotal(int Magic)
{
  int c=0;
  int total  = OrdersTotal();

  for (int cnt = 0 ; cnt < total ; cnt++)
  {
    OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
    if (OrderMagicNumber() == Magic && OrderSymbol()==Symbol())
    {
      c++;
    }
  }
  return(c);
}


Err_138

avatar
735
honest_knave 2015.12.28 22:45 #
 

Error code 138 is a requote - see here and here

Calculated or unnormalized price cannot be applied. If there has not been the requested open price in the price thread or it has not been normalized according to the amount of digits after decimal point, the error 129 (ERR_INVALID_PRICE) will be generated. If the requested open price is fully out of date, the error 138 (ERR_REQUOTE) will be generated independently on the slippage parameter. If the requested price is out of date, but present in the thread, the order will be opened at the current price and only if the current price lies within the range of price+-slippage.

 Try RefreshRates() before doing your OrderSend

avatar
Moderator
3412
GumRai 2015.12.28 22:59 #
 
LastPrice+Step*Point*pt
is unlikely to be a valid price. Open a Buy at Ask and a Sell at Bid.
avatar
735
honest_knave 2015.12.28 23:38 #
 
Good spot GumRai. I only looked as far as the first OrderSend.
avatar
2
andy1979 2015.12.29 10:24 #
 
GumRai:
is unlikely to be a valid price. Open a Buy at Ask and a Sell at Bid.
thank you for your correction GumRai..but i want to place order sell above order buy...any idea...??
avatar
Moderator
3412
GumRai 2015.12.29 10:37 #
 
andy1979:
thank you for your correction GumRai..but i want to place order sell above order buy...any idea...??
Place a limit sell
avatar
735
honest_knave 2015.12.29 13:36 #
 
Take a look here too
Back to topics list  

To add comments, please log in or register