please help to resolve "not all control paths return a value" error

To add comments, please log in or register
Masha
11
Masha  

Hi, I moved to new computer and was forced to install a new built of MT4 way above 600. Almost all my compiled scripts are working, but those that don't return the same error: "not all control paths  return a value". In theory I understnad what it might mean, but with my basic programming skills I can't find where exactly am I missing some cases and why before it was alright. for example this script below doesn't even have if-else in it and still returns the same error:


Please help e to fix it.

double risk;

string pairall[8]={"SGDJPY","NZDUSD","AUDUSD","CADJPY","USDJPY","CHFJPY","EURUSD","GBPUSD"};
string lotall[8];
string spreadall[8];
string pairM[4]={"NZDUSD","AUDUSD","USDJPY","EURUSD"};
string lotM[4];
string spreadM[4];
int i, j;
string mytext, mytextM;


int start()
{
risk = GlobalVariableGet("risk");

i=0;
mytext="With risk ="+DoubleToStr(risk,2)+"\r \r symbol      lot    spread";
while(i<ArrayRange(pairall,0))
   {
   lotall[i] = DoubleToStr(risk*AccountFreeMargin()/MarketInfo(pairall[i],MODE_MARGINREQUIRED),2);
   spreadall[i] = DoubleToStr(MarketInfo(pairall[i],MODE_SPREAD)/10,1);
   mytext=mytext+"\r "+pairall[i]+"    "+lotall[i]+"    "+spreadall[i];
   i++;}

j=0;
mytextM="\r";
while(j<ArrayRange(pairM,0))
   {
   lotM[j] = DoubleToStr(risk*AccountFreeMargin()/MarketInfo(pairM[j],MODE_MARGINREQUIRED),2);
   spreadM[j] = DoubleToStr(MarketInfo(pairM[j],MODE_SPREAD)/10,1);
   mytextM=mytextM+"\r "+pairM[j]+"    "+lotM[j]+"    "+spreadM[j];
   j++;}

MessageBox(mytext+mytextM,NULL,EMPTY);

}
honest_knave
Moderator
2308
honest_knave  
double risk;

string pairall[8]={"SGDJPY","NZDUSD","AUDUSD","CADJPY","USDJPY","CHFJPY","EURUSD","GBPUSD"};
string lotall[8];
string spreadall[8];
string pairM[4]={"NZDUSD","AUDUSD","USDJPY","EURUSD"};
string lotM[4];
string spreadM[4];
int i, j;
string mytext, mytextM;


int start()
{
risk = GlobalVariableGet("risk");

i=0;
mytext="With risk ="+DoubleToStr(risk,2)+"\r \r symbol      lot    spread";
while(i<ArrayRange(pairall,0))
   {
   lotall[i] = DoubleToStr(risk*AccountFreeMargin()/MarketInfo(pairall[i],MODE_MARGINREQUIRED),2);
   spreadall[i] = DoubleToStr(MarketInfo(pairall[i],MODE_SPREAD)/10,1);
   mytext=mytext+"\r "+pairall[i]+"    "+lotall[i]+"    "+spreadall[i];
   i++;}

j=0;
mytextM="\r";
while(j<ArrayRange(pairM,0))
   {
   lotM[j] = DoubleToStr(risk*AccountFreeMargin()/MarketInfo(pairM[j],MODE_MARGINREQUIRED),2);
   spreadM[j] = DoubleToStr(MarketInfo(pairM[j],MODE_SPREAD)/10,1);
   mytextM=mytextM+"\r "+pairM[j]+"    "+lotM[j]+"    "+spreadM[j];
   j++;}

MessageBox(mytext+mytextM,NULL,EMPTY);

return(0);
}
Masha
11
Masha  
Wow, that's the only thing missing?! Thank you very much! I suppose I can fix that way all my scripts. Perfect!
Alain Verleyen
38701
Alain Verleyen  
badmash:
Wow, that's the only thing missing?! Thank you very much! I suppose I can fix that way all my scripts. Perfect!
https://www.mql5.com/en/articles/1391#1_4
milad najjari
109
milad najjari  

hello everyone please help to fix this:

bool orderprofit()

{
 for(int i=OrdersTotal()-1;i>=0;i--)
   {
    if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
     {    
       if((OrderType()==OP_BUY && OrderOpenPrice()<Bid ) || (OrderType()==OP_SELL && OrderOpenPrice()>Ask))
        return(True);        
        else      
        return(False);     
     }    
   }  
}


but give me this error ""not all control paths  return a value""

Marco vd Heijden
Moderator
12729
Marco vd Heijden  
milad najjari:

hello everyone please help to fix this:

bool orderprofit()

{
 for(int i=OrdersTotal()-1;i>=0;i--)
   {
    if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
     {    
       if((OrderType()==OP_BUY && OrderOpenPrice()<Bid ) || (OrderType()==OP_SELL && OrderOpenPrice()>Ask))
        return(True);        
        else      
        return(False);     
     }    
   }  
}


but give me this error ""not all control paths  return a value""

Because it doesn't return anything when orderselect fails.

bool orderprofit()

{
 for(int i=OrdersTotal()-1;i>=0;i--)
   {
    if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
     {     
       if((OrderType()==OP_BUY && OrderOpenPrice()<Bid ) || (OrderType()==OP_SELL && OrderOpenPrice()>Ask))
        return(True);                      
     }     
   }
  return(False);  
}
milad najjari
109
milad najjari  
Marco vd Heijden:

Because it doesn't return anything when orderselect fails.


thanks
To add comments, please log in or register