# Error 138 and modify order

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

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 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++ ) {
if( OrderSymbol() == Symbol() ) {
LastPrice = OrderOpenPrice();
}
}
if (MyOrdersTotal(Magic)==0)
{
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++)
{
if (OrderMagicNumber() == Magic && OrderSymbol()==Symbol())
{
c++;
}
}
return(c);
}

Moderator
2373

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

Moderator
10376

LastPrice+Step*Point*pt
is unlikely to be a valid price. Open a Buy at Ask and a Sell at Bid.
Moderator
2373

Good spot GumRai. I only looked as far as the first OrderSend.
13

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...??
Moderator
10376

andy1979:
thank you for your correction GumRai..but i want to place order sell above order buy...any idea...??
Place a limit sell
Moderator
2373

Take a look here too