Download MetaTrader 5
To add comments, please log in or register
Do you want to become a well-known developer? Execute the orders of traders in the Freelance service!
siladeh
51
siladeh 2014.04.03 04:49 

Hello, I am trying to code my system however after compiling it returns the "not all control paths return a value" and when I double click it shows its in the following block, could someone please point out the problem.

Thank you in advance

bool CalculateCurrentSellOrders(string symbol)
  {
   int sells=0;
   for (int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MAGICMA)
        {
         if(OrderType()==OP_SELL) sells++;
        }
      }
   if(sells>0) return(true);
  }
siladeh
51
siladeh 2014.04.03 06:10  
Siladeh:

Hello, I am trying to code my system however after compiling it returns the "not all control paths return a value" and when I double click it shows its in the following block, could someone please point out the problem.

Thank you in advance


Problem solved


Remove #Property strict

Keith Watford
Moderator
7948
Keith Watford 2014.04.03 06:34  
Siladeh:

Problem solved


Remove #Property strict


That's a work around, add 1 extra line

   if(sells>0) return(true);
   else     return(false);  // Add this line
siladeh
51
siladeh 2014.04.03 10:26  
GumRai:


That's a work around, add 1 extra line


Thank you buddy
whroeder1
13619
whroeder1 2014.04.03 13:28  
Or the simpler:
return( sells>0 );
// if(sells>0) return(true);                
// else     return(false);  // Add this line
Toast
220
Toast 2014.04.03 13:39  

WHRoeder - I keep stripping more lines out of my code thanks to your tips. I would have done exactly the same as GumRai. Thanks!

Daniel Petrovai
440
Daniel Petrovai 2014.04.06 04:09  
GumRai:


That's a work around, add 1 extra line


Hi GumRai, just for the sake of conversation, you don't really need the else in there, right ? : )

   if(sells>0) return(true);
   return(false); 
Daniel Petrovai
440
Daniel Petrovai 2014.04.06 04:32  
Siladeh:

Hello, I am trying to code my system however after compiling it returns the "not all control paths return a value" and when I double click it shows its in the following block, could someone please point out the problem.

Thank you in advance

You may get a warning for OrderSelect if you don't check the result.

bool CalculateCurrentSellOrders(string symbol)
  {
   int sells=0;
   for (int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)
        Print("OrderSelect() failed with error : "+GetLastError());
      if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=MAGICMA)continue;
      if(OrderType()==OP_SELL) sells++;
     }
   if(sells>0) return(true);
   return(false);
  }


Hope it helps

Keith Watford
Moderator
7948
Keith Watford 2014.04.06 07:00  
thrdel:


Hi GumRai, just for the sake of conversation, you don't really need the else in there, right ? : )


No, you're right.

WHRoeders post above yours is even simpler to achieve the same thing

Daniel Petrovai
440
Daniel Petrovai 2014.04.06 07:18  
GumRai:


No, you're right.

WHRoeders post above yours is even simpler to achieve the same thing


True, but only for particular situations like this one. The other way is more general, regardless of how many and what conditions are, if none of them return true, it will return false.

It is, must admit, an elegant solution for this particular example.

Alain Verleyen
Moderator
28606
Alain Verleyen 2014.04.06 09:49  
thrdel:

...

and if you don't use :

Hope it helps

You don't need to add -1 as the condition is
i<OrdersTotal()
If you add -1 you miss 1 item of the array.
/
To add comments, please log in or register