OrderSend error 129 - page 2

 
tzm:

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!





Dear Raptor,


I noticed your demand for using the SRC button to make the contents tidy and clean. I will use it carefully later on to make the contents more readable and more comprehensible.Sorry for the trouble aroused.
 

tzm: 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.

Well I'm happy its working for you :)

You take all the credits buddy .... way to hang in here.

 
tzm: ask1 to normalize it before
  1. Never use NormalizeDouble. Price must be normalized for pending orders
  2. Not adjusting stops for 4/5 digit
  3. No adjusted slippage
  4. Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial