OrderSend error 129

 
void OpenOrdersToTP()
{
  //to place orders so as to TP in choppy markets.
  RefreshRates();
  double point=MarketInfo(Symbol(),MODE_POINT);
  Print("in OpenOrdersToTP():Bid=",DoubleToStr(Bid,Digits), ",Ask=",DoubleToStr(Ask,Digits));
  int ticketBuy=OrderSend(Symbol(),OP_BUY, initialLotz, Ask, 3, 0,Ask+Grid.StepHeight*point,"", MAGICNOForChoppyMarket,0,0);  
  if(ticketBuy<0)
    Alert("in OpenOrdersToTP() OP_BUY, ordersend failed:",GetLastError(),
      "OpenPrice=",DoubleToStr(Ask,Digits),
      "TP=",DoubleToStr(Ask-Grid.StepHeight*point,Digits));
  else Alert("in OpenOrdersToTP() OP_BUY, OK");

  int ticketSell=OrderSend(Symbol(),OP_SELL, initialLotz, Bid, 3, 0,Bid-((Grid.StepHeight)*point),"", MAGICNOForChoppyMarket,0,0);
  if(ticketSell<0)
    Alert("in OpenOrdersToTP() OP_SELL, ordersend failed:",GetLastError(),
      "Bid=",DoubleToStr(Bid,Digits),
      "TP=",DoubleToStr(Bid-Grid.StepHeight*point,Digits));
  else Alert("in OpenOrdersToTP() OP_SELL, OK");
}

 
tzm: Thank you for your prompt reply. I cannot find my original post. I can only see the "CODE REMOVED" statement. So I added the code with the SRC button. The script was attached below for you to conveniently show the 129 error. Thank you again.

Are you getting this error message live?

Are you running this ea live upon more than 1 symbol?

 
ubzen:

Are you getting this error message live?

Are you running this ea live upon more than 1 symbol?


Dear Ubzen,

The error was reported when I tried to test an EA with a demo account in realtime.Currently, I only run the EA and the script on EURUSD. Thanks a lot for your concern.

RaptorUK:
Why didn't you simply edit the code using the SRC button into your first post as requested ?

Dear Raptor,


I cannot see my orginal post. so I have no way to edit the code.

 
tzm: The error was reported when I tried to test an EA with a demo account in realtime.Currently, I only run the EA and the script on EURUSD. Thanks a lot for your concern.
Well try some debugging. For example printing the Prices used within the OrderClose() and OrderSend() functions. You're not checking OrderSymbol() and you're not checking that the OrderSelect() worked. I recommend doing those.
 
ubzen:
Well try some debugging. For example printing the Prices used within the OrderClose() and OrderSend() functions. You're not checking OrderSymbol() and you're not checking that the OrderSelect() worked. I recommend doing those.

Dear Ubzen,


Thanks a lot for your consideration. I have taken everything away from the code in the attached script(https://c.mql5.com/mql4/forum/2013/11/testropenordertoTP.mq4) so it only includes two statements-ordersend for a OP_BUY and ordersend for a OP_SELL order but the terminal still report error 129!

 
tzm: Thanks a lot for your consideration. I have taken everything away from the code in the attached script(https://c.mql5.com/mql4/forum/2013/11/testropenordertoTP.mq4) so it only includes two statements-ordersend for a OP_BUY and ordersend for a OP_SELL order but the terminal still report error 129!
Insert the two statements you used here.
 
ubzen:
Insert the two statements you used here.



Dear Ubzen,

the two statemens are commented below with "STATEMETNT 1" and "STATEMETNT 2" at the end of their lines.
void OpenOrdersToTP()
{
  //to place orders so as to TP in choppy markets.
  RefreshRates();
  double point=MarketInfo(Symbol(),MODE_POINT);
  double ask1=0.0,bid1=0.0;
  double tpbuy=0.0, tpsell=0.0;
  
  ask1=NormalizeDouble(Ask,Digits);
  bid1=NormalizeDouble(Bid,Digits);
  tpbuy=NormalizeDouble(Ask+Grid.StepHeight*point,Digits);
  tpsell=NormalizeDouble(Bid-Grid.StepHeight*point,Digits);
  Print("in OpenOrdersToTP():Bid=",DoubleToStr(Bid,Digits), ",Ask=",DoubleToStr(Ask,Digits));
  int ticketBuy=OrderSend(Symbol(),OP_BUY, initialLotz, ask1, 3, 0,tpbuy,"", MAGICNOForChoppyMarket,0,0);  //STATEMENT 1 .
  if(ticketBuy<0)
    Alert("in OpenOrdersToTP() OP_BUY, ordersend failed:",GetLastError(),
      "OpenPrice=",DoubleToStr(ask1,Digits),
      "TP=",DoubleToStr(tpbuy,Digits));
  else Alert("in OpenOrdersToTP() OP_BUY, OK");

  tpsell=NormalizeDouble(Bid-Grid.StepHeight*point,Digits);
  int ticketSell=OrderSend(Symbol(),OP_SELL, initialLotz,bid1, 3, 0,tpsell,"", MAGICNOForChoppyMarket,0,0);  //STATEMENT 2
  if(ticketSell<0)
    Alert("in OpenOrdersToTP() OP_SELL, ordersend failed:",GetLastError(),
      "Bid=",DoubleToStr(bid1,Digits),
      "TP=",DoubleToStr(tpsell,Digits));
  else Alert("in OpenOrdersToTP() OP_SELL, OK");
}
 

Im looking for the compiled version of the Expert with the two lines... the above is more than two lines and its just a duplicate of that you attached before. Here I'll do the two lines for you. You go ahead and test this ... if you get the same error message then contact your broker.

void start(){
    double  BrkMinLot=MarketInfo(Symbol(),MODE_MINLOT);
    int Ticket=OrderSend(Symbol(),OP_BUY,BrkMinLot,Ask,0,0,0,"",0,0,0);
    if(Ticket<0) Print("Error Processing Order=",GetLastError());
}
 
OrderSend(Symbol(),OP_BUY, initialLotz, ask1, 3, 0,tpbuy,"", MAGICNOForChoppyMarket,0,0);

Why are you using ask1 instead of just ask? Do-Not ..... NormalizeDouble(Ask,Digits); there's no need.

 
tzm:

Raptor and WHRoeder,

I followed raptor's instruction and click the "edit" link, but my original post didnot appeared!.Here I re-paste code relevant for you to help me find out the cause of the "ordersend error 129". Thanks in advance for your time and consideration.

I removed your original code . .. hence the <CODE REMOVED> which you were able to edit and remove, why didn't you simply paste your code back in using the SRC button ?
 
ubzen:

Why are you using ask1 instead of just ask? Do-Not ..... NormalizeDouble(Ask,Digits); there's no need.


Dear Ubzen, Raptor and WHRoeder,
Many thanks for your instruction.

I use ask1 to normalize it before using it in the ordersend function. Based on the code snippet in your previous reply, I modify the code in the original post, no 129 error was reported again. I repost the code snippet here in case it might be of help to someone. The key is to call refreshrates() before the call to any OrderSend(). Since any trading function call will cost some time to finish, calling this function can ensure the market data refresh.

Below is the code that works currently, with RefreshRates() added before the OP_SELL orderSend call, no OrderSend Error 129 was reported again.

void OpenOrdersToTP()
{
  //to place orders so as to TP in choppy markets.
  RefreshRates();
  double point=MarketInfo(Symbol(),MODE_POINT);
  double ask1=0.0,bid1=0.0;
  double tpbuy=0.0, tpsell=0.0;
  
  RefreshRates();
  ask1=NormalizeDouble(Ask,Digits);
  bid1=NormalizeDouble(Bid,Digits);
  tpbuy=NormalizeDouble(Ask+Grid.StepHeight*point,Digits);//Grid.StepHeight是个全局变量,被初始化为50。
  Print("in OpenOrdersToTP():Bid=",DoubleToStr(Bid,Digits), ",Ask=",DoubleToStr(Ask,Digits));
  int ticketBuy=OrderSend(Symbol(),OP_BUY, initialLotz, Ask, 0, 0,tpbuy,"", MAGICNOForChoppyMarket,0,0);  
  if(ticketBuy<0)
    Alert("in OpenOrdersToTP() OP_BUY, ordersend failed:",GetLastError(),
      "OpenPrice=",DoubleToStr(ask1,Digits),
      "TP=",DoubleToStr(tpbuy,Digits));
  else Alert("in OpenOrdersToTP() OP_BUY, OK");

  RefreshRates();// call this to keep the market data refresh, without it Error 129 will be occur!
  tpsell=NormalizeDouble(Bid-Grid.StepHeight*point,Digits);
  int ticketSell=OrderSend(Symbol(),OP_SELL, initialLotz,Bid, 0, 0,tpsell,"", MAGICNOForChoppyMarket,0,0);
  if(ticketSell<0)
    Alert("in OpenOrdersToTP() OP_SELL, ordersend failed:",GetLastError(),
      "Bid=",DoubleToStr(bid1,Digits),
      "TP=",DoubleToStr(tpsell,Digits));
  else Alert("in OpenOrdersToTP() OP_SELL, OK");
}

Thank you all again for your time and efforts! Good luck to you all. This question really make me somewhat exhausted!


RaptorUK:
I removed your original code . .. hence the <CODE REMOVED> which you were able to edit and remove, why didn't you simply paste your code back in using the SRC button ?

RaptorUK:
I removed your original code . .. hence the <CODE REMOVED> which you were able to edit and remove, why didn't you simply paste your code back in using the SRC button ?
Reason: