0
votes

I get ordersend error 138, be it buy or sell, but only in back testing not in live demo. I have try to adjust slippage to no avail. Does anyone have any idea what's wrong?

double price = iClose(Symbol(), PERIOD_H1, 1);
   if (up > down && up > sideway){
      double stoploss = NormalizeDouble(price-piploss*Point, Digits);
      double takeprofit = NormalizeDouble(price+pipgain*Point, Digits);
      int ticket = OrderSend(Symbol(), OP_BUY, 1, price, 5, stoploss, takeprofit, "buy", 16384, 0, clrGreen);
      if (ticket<0){
         Print("Order send error: ", GetLastError());
      } else{
         Print("Order success");
      }
   } else if (down > up && down > sideway) {
      double stoploss = NormalizeDouble(price+piploss*Point, Digits);
      double takeprofit = NormalizeDouble(price-pipgain*Point, Digits);
      int ticket = OrderSend(Symbol(), OP_SELL, 1, price, 5, stoploss, takeprofit, "sell", 16384, 0, clrGreen);
      if (ticket<0){
         Print("Order send error: ", GetLastError());
      } else{
         Print("Order success");
      }
   } else {
      Print("sideway");
   }
     }
1

1 Answers

3
votes

Your price is close of the previous H1 candle. Probably you do open bar check before. Anyway, your computation may take time, that is why it is strongly recommended to RefreshRates() before sending the order. Next, you should use constants Ask and Bid when sending market orders, they are updated after refreshing rates. Otherwise you receive different errors (133, 136, 138).