Download MetaTrader 5
To add comments, please log in or register
Examine the Top MetaTrader 5 signals. Choose the best one and subscribe to it!
Tan Phan Ngoc
1332
Tan Phan Ngoc 2014.09.11 12:46 

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
17335
Stanislav Korotky 2014.09.11 20:47  
What's the problem? Compiler advises you to check resulting codes of the abovementioned functions. Just do it.
Irwan Adnan
876
Irwan Adnan 2014.09.12 04:31  

I solved that by using variables, such as 

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

Kirill Garmash
249
Kirill Garmash 2014.09.12 18:40  

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
4403
Ndumiso Mavuso 2015.11.01 06:34  
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
123
johnnyp 2016.08.21 11:48  
Thanks for this to Ndumiso (last post) , as Im a novice!
/
To add comments, please log in or register