Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 472

 

'}' - not all control paths return a value

highlights such an error in the function..... though it returns a value and works fine in another indicator without this error


 
Zver4991:

'}' - not all control paths return a value

highlights such an error in the function..... though it returns a value and works fine in another indicator without this error



Open in a new editor, highlight the first bracket and check the last one, you will see everything at once.
 

Can you tell me if it is possible to arrange a step-by-step run of the program in debug mode? And add more variables for tracking

 
Zver4991:

'}' - not all control paths return a value

the function..... although it returns a value and works fine in another indicator without this error


This is a message telling you that there are branching options in the function when it might not return anything. For example:

//+----------------------------------------------------------------------------+
int TestFunc(int a) {
   if(a>2 || a<0) a=2;
   if(a==0) return(1);
   else if(a==1) return(2);
   else if(a==2) return(3);
}
//+----------------------------------------------------------------------------+

The value of the a variable seems to be limited in the range from 0 to 2, but the compiler still considers this an error.

Put return() with default return value from the function before the closing parenthesis of the function body and everything will be fine:

//+----------------------------------------------------------------------------+
int TestFunc(int a) {
   if(a>2 || a<0) a=2;
   if(a==0) return(1);
   else if(a==1) return(2);
   else if(a==2) return(3);
   return(-1);
}
//+----------------------------------------------------------------------------+
 
artmedia70:

This tells you that there are branching options in the function when it may not return anything. For example:

The a variable's value seems to be limited in the range from 0 to 2, but the compiler still considers it an error.

Put return() before the closing parenthesis of the function body with the default return value from the function and all will be grain gut:


What if a is not an int type?

function type - return value at the end of the function

int  - return(-1);

void - return;

bool - return(false);

string - return(""); 
 
artmedia70:

This tells you that there are branching options in the function when it may not return anything. For example:

The value of variable a seems to be limited to a range from 0 to 2, but the compiler still considers it an error.

Put return() before the closing parenthesis of the function body with the default return value from the function and all will be grain gut:


thanks a lot..... saved my nerves
 
Vladon:


What if a person's type is not int?

the function type is the return result at the end of the function


What was that about? I just gave an example - the first thing that popped into my head. You could have written a function returning any other data type (except void)... It doesn't change the point.
 
artmedia70:
What was that about? I just gave an example - the first thing that popped into my head. You could have written a function returning any other data type (except void)... It doesn't change the point.


I was just clarifying the data type. This is a branch of questions from newbies, so they expect the same return in any function
 

Help with the bugs!

I decided to make an EA for myself on the basis of an example from the mql4 manual. I've been messing with it for a week now, but it always gives me some kind of error.

Please check what may be wrong, maybe something should be changed or removed in addition to brackets.

Errors:

'}' - unexpected end of program expert.mq4 218 3

'{' - unbalanced parentheses expert.mq4 23 2

Files:
expert_1.mq4  9 kb
 
Kutuzov:

Help with the bugs!

I decided to make an EA for myself on the basis of an example from the mql4 manual. I've been messing with it for a week now, but it always gives me some kind of error.

Please check what may be wrong, maybe something should be changed or removed in addition to brackets.

Errors:

'}' - unexpected end of program expert.mq4 218 3

'{' - unbalanced parentheses expert.mq4 23 2


Try translating what is written in the errors. I think this is the easiest way to find out the cause of the error

What does this do at the start?

#property  indicator_level1 20 // Задаём верхний уровень                             
#property  indicator_level2 80 // Задаём нижний уровень 

You have an Expert Advisor, not an indicator.

 DPeriod,      // "Redline" индикатора StochRSI.mq4 
 DPeriod=Bid;   // Запрашивем значение "Redline"

why isn't the type specified?

  return;      // Выход из start()

where is the closing parenthesis?

 };

What is this news?

Show me where it is written in the example?

bool Ans =false,  // Ответ сервера после закрытия
bool Cls_B=false,

why is there a comma at the end and not a semicolon? why write the same thing twice?

You put a comma, write it that way:

bool Ans =false,  // Ответ сервера после закрытия
 Cls_B=false, // Критерий для закрытия Buy
 Cls_S=false, // Критерий для закрытия Sell
 Opn_B=false, // Критерий для открытия Buy
 Opn_S=false; // Критерий для открытия Sell

What is it?

[1]Close

I didn't look any further, I got tired,

So don't blame the mistakes. They're due to your inattention. You need to read the help once again, and watch the video to read an article on how to program in this language.

Reason: