A question for MQL experts - page 15

 

Thank you Zhunko and TheXpert !

Your variants eliminate this type of error!

 

Hi!

Can you tell me what the warning may mean when compiling an indicator in an updated mt4:

not all control paths return a value S_E_v.mq4 181
0 error(s), 1 warning(s) 1 2

 
Rita:

Can you tell me what the warning might mean when compiling the indicator in the updated mt4:

It means that there is a case where nothing is returned in the function that returns a value and this is bad.
 

Programmers, help me out: I need to determine the bar offset for a given time on an hourly TF. The standard procedure (from the tutorial) gives 0. Point me in the wrong direction...

 datetime some_time=D'2004.03.21 12:00';
  int      shift=iBarShift("EUROUSD",PERIOD_M1,some_time);
  Print("shift of bar with open time ",TimeToStr(some_time)," is ",shift);
 
Nesradamus:

Programmers, help me out: I need to determine the bar offset for a given time on an hourly TF. The standard procedure (from the tutorial) gives 0. Point me in the wrong direction...

"EUROUSD"

Is there such a symbol?

 

Afternoon.

After the last mt4 update and EA compilation there are warnings in three lines 101-106-109, see fig:

Please advise, - how to fix, here is the code of this function :

(and should it be corrected?)

int init()
{
 ExpertBars = Bars;
//-----------------------------------------------------------
gbNoInit=False; if (!IsTradeAllowed()) {
    Message("Для нормальной работы советника необходимо\n"+
            "Разрешить советнику торговать");
    gbNoInit=True; return;
  }
  if (!IsLibrariesAllowed()) {
    Message("Для нормальной работы советника необходимо\n"+
            "Разрешить импорт из внешних экспертов");
    gbNoInit=True; return;
  }
//------------------
}
 
Rita:

Afternoon. After the last mt4 update and EA compilation there are warnings in three lines 101-106-109, see fig:

Please advise, - how to fix, here is the code of this function :

(and should it be corrected?)

Your init() is of int type, which means it needs to return a value. Before the last closing parenthesis write

return(INIT_SUCCEEDED);

There is a place in one function where the function may return nothing. You have not shown the functions - search for yourself in those functions where leaving on the last closing parenthesis is possible.

 
Here is the code
artmedia70:

.Before the last closing parenthesis, write .....

You didn't show the functions - search for yourself in those functions where leaving on the last closing parenthesis is possible.


Thank you. Corrected return(INIT_SUCCEEDED);.

Here is the code of this unshown function for the other two remaining warnings:

//+----------------------------------------------------------------------------+
//|  Вывод сообщения в коммент и в журнал                                      |
//+----------------------------------------------------------------------------+
void Message(string m) {
  Comment(m);
  if (StringLen(m)>0) Print(m);}

.

 
Rita:
Here is the code

Thank you. Corrected.

Here is the code for this function on the other two warnings:

1. Most likely, you have deinit() also int and return(0) is not written in it

2. This function is void and the closing parenthesis serves as return` in it. Everything is ok in it.

 

deinit() - I don't have it at all.

Fixed return to return(0) on the two remaining warnings and the code compiled without any issues.

Thank you.