Download MetaTrader 5

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

To add comments, please log in or register
Move from theory to practice. Code Base will help you!
Masha
8
Masha 2014.05.27 05:43 

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
2213
honest_knave 2014.05.27 09:01  
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
8
Masha 2014.05.27 15:25  
Wow, that's the only thing missing?! Thank you very much! I suppose I can fix that way all my scripts. Perfect!
Alain Verleyen
Moderator
30739
Alain Verleyen 2014.05.27 15:57  
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
To add comments, please log in or register