Download MetaTrader 5

Debug: return value of 'OrderSelect' should be checked

To add comments, please log in or register
Tan Phan Ngoc
1331
Tan Phan Ngoc  

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;
                  }
               }
            }
         }
      }
   }
Stanislav Korotky
19878
Stanislav Korotky  
What's the problem? Compiler advises you to check resulting codes of the abovementioned functions. Just do it.
Irwan Adnan
921
Irwan Adnan  

I solved that by using variables, such as 

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

Kirill Garmash
249
Kirill Garmash  

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 )

{

   ...

Ndumiso Mavuso
4565
Ndumiso Mavuso  
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;
                  }
               }
            }
         }
      }
   }
johnnyp
142
johnnyp  
Thanks for this to Ndumiso (last post) , as Im a novice!
To add comments, please log in or register