Debug: return value of 'OrderSelect' should be checked

 

I have a problem about debug. Could you help me?

return value of 'OrderSelect' should be checked    MA.1.mq4    111    7
return value of 'OrderClose' should be checked    MA.1.mq4    131    16
return value of 'OrderModify' should be checked    MA.1.mq4    141    22
return value of 'OrderClose' should be checked    MA.1.mq4    161    16
return value of 'OrderModify' should be checked    MA.1.mq4    171    22
0 error(s), 5 warning(s)        1    6
//Check position
   bool IsTrade = False;

   for (int i = 0; i < Total; i ++) {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      
      if ( OrderMagicNumber() != MagicNumber ) continue;
      
      if(OrderType() <= OP_SELL &&  OrderSymbol() == Symbol()) {
         IsTrade = True;
         if(OrderType() == OP_BUY) {
            //Close

            //+------------------------------------------------------------------+
            //| Signal Begin(Exit Buy)                                           |
            //+------------------------------------------------------------------+

            

            //+------------------------------------------------------------------+
            //| Signal End(Exit Buy)                                             |
            //+------------------------------------------------------------------+

            if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
               OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
               if (!EachTickMode) BarCount = Bars;
               IsTrade = False;
               continue;
            }
            //Trailing stop
            if(UseTrailingStop && TrailingStop > 0) {                 
               if(Bid - OrderOpenPrice() > point * TrailingStop) {
                  if(OrderStopLoss() < Bid - point * TrailingStop) {
                     OrderModify(OrderTicket(), OrderOpenPrice(), Bid - point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
                     if (!EachTickMode) BarCount = Bars;
                     continue;
                  }
               }
            }
         } else {
            //Close

            //+------------------------------------------------------------------+
            //| Signal Begin(Exit Sell)                                          |
            //+------------------------------------------------------------------+

            

            //+------------------------------------------------------------------+
            //| Signal End(Exit Sell)                                            |
            //+------------------------------------------------------------------+

            if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
               OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
               if (!EachTickMode) BarCount = Bars;
               IsTrade = False;
               continue;
            }
            //Trailing stop
            if(UseTrailingStop && TrailingStop > 0) {                 
               if((OrderOpenPrice() - Ask) > (point * TrailingStop)) {
                  if((OrderStopLoss() > (Ask + point * TrailingStop)) || (OrderStopLoss() == 0)) {
                     OrderModify(OrderTicket(), OrderOpenPrice(), Ask + point * TrailingStop, OrderTakeProfit(), 0, DarkOrange);
                     if (!EachTickMode) BarCount = Bars;
                     continue;
                  }
               }
            }
         }
      }
   }
 
What's the problem? Compiler advises you to check resulting codes of the abovementioned functions. Just do it.
 

I solved that by using variables, such as 

ordcls = OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen); 

 

Hello. I usually write something like this:

while ( true )

{

   if ( OrderClose(...) == true )

   {

      break; 

   } 

   else 

   {

      if ( CheckErrors( GetLastError() ) == true )   //CheckErrors() - your function

      {

         continue; 

      } 

      else

      {

         break; 

      } 

   } 

or just like this:

if ( OrderSelect(...) == true )

{

   ...

 
Tan Phan Ngoc:

I have a problem about debug. Could you help me?

Just Check, Why Not?

//Check position
   bool IsTrade = False;

   for (int i = 0; i < Total; i ++) {
      if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
         continue;
      
      if ( OrderMagicNumber() != MagicNumber ) continue;
      
      if(OrderType() <= OP_SELL &&  OrderSymbol() == Symbol()) {
         IsTrade = True;
         if(OrderType() == OP_BUY) {
            //Close

            //+------------------------------------------------------------------+
            //| Signal Begin(Exit Buy)                                           |
            //+------------------------------------------------------------------+

            

            //+------------------------------------------------------------------+
            //| Signal End(Exit Buy)                                             |
            //+------------------------------------------------------------------+

            if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
               if(!OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen))
                Print("OrderClose error ",GetLastError());
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
               if (!EachTickMode) BarCount = Bars;
               IsTrade = False;
               continue;
            }
            //Trailing stop
            if(UseTrailingStop && TrailingStop > 0) {                 
               if(Bid - OrderOpenPrice() > point * TrailingStop) {
                  if(OrderStopLoss() < Bid - point * TrailingStop) {
                     if(!OrderModify(OrderTicket(), OrderOpenPrice(), Bid - point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen))
                        Print("OrderModify error ",GetLastError());
                     if (!EachTickMode) BarCount = Bars;
                     continue;
                  }
               }
            }
         } else {
            //Close

            //+------------------------------------------------------------------+
            //| Signal Begin(Exit Sell)                                          |
            //+------------------------------------------------------------------+

            

            //+------------------------------------------------------------------+
            //| Signal End(Exit Sell)                                            |
            //+------------------------------------------------------------------+

            if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
               if(!OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange))
                   Print("OrderClose error ",GetLastError());
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
               if (!EachTickMode) BarCount = Bars;
               IsTrade = False;
               continue;
            }
            //Trailing stop
            if(UseTrailingStop && TrailingStop > 0) {                 
               if((OrderOpenPrice() - Ask) > (point * TrailingStop)) {
                  if((OrderStopLoss() > (Ask + point * TrailingStop)) || (OrderStopLoss() == 0)) {
                     if(!OrderModify(OrderTicket(), OrderOpenPrice(), Ask + point * TrailingStop, OrderTakeProfit(), 0, DarkOrange))
                       Print("OrderModify error ",GetLastError());;
                     if (!EachTickMode) BarCount = Bars;
                     continue;
                  }
               }
            }
         }
      }
   }
 
Thanks for this to Ndumiso (last post) , as Im a novice!
 

hello can help me too I have the same problem here in the recovery value

<decompiled code removed>
 
visioneduar: <decompiled code removed>

Ask the owner of the source code to give it to you or have him fix it for you.

Decompiled code is stolen code. Either you are a thief, a fence, or the receiver of stolen (intellectual) property. Either way we will not be an accomplice after the fact to theft.
          See also forum.MQL4.com/41864#490649

If you post decompiled code again, you will likely be banned.

Don't tell us you found it on the 'net: if someone stole your bank details and uploaded them on to the internet, is it OK for everyone to use them because "someone uploaded it, I don't know why I can't use that"?

 

how to fix?

return value of 'OrderClose' should be checked

 // Custom function to close all open positions
void CloseAllPositions() {
    for (int i = OrdersTotal() - 1; i >= 0; i--) {
        if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
            if (OrderSymbol() == Symbol()) {
                OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3,clrRed);
                positionsCount--;
            }
        }
    } 
 
robertreyt #: how to fix?

return value of 'OrderClose' should be checked

  1. Don't hijack other threads for your off-topic post. Next time, make your own, new, thread.
  2. How did you check your OrderSelect call?