"Not all control paths return a value" error

To add comments, please log in or register
siladeh
63
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

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
63
siladeh  
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
20477
Keith Watford  
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
63
siladeh  
GumRai:


That's a work around, add 1 extra line


Thank you buddy
William Roeder
20228
William Roeder  
Or the simpler:
return( sells>0 );
// if(sells>0) return(true);                
// else     return(false);  // Add this line
Toast
227
Toast  

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
412
Daniel Petrovai  
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
412
Daniel Petrovai  
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
20477
Keith Watford  
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
412
Daniel Petrovai  
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
38701
Alain Verleyen  
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.
123
To add comments, please log in or register