Questions from Beginners MQL4 MT4 MetaTrader 4 - page 201

 
Alexsandr San:

Do you want it for mt4 or mt5? I deleted the code I posted. I did not immediately notice that mt4 was discussed here

MQL4

 
Speculator:

MQL4

Here, a lot of good stuffhttps://www.mql5.com/ru/forum/131859/page6#comment_3359705
 
Hi, is it possible to receive phone/email notifications in MT4 when the terminal is switched off, but with a VPS server connected?
 
Alexsandr San:

I advise you - there are a lot of good things to findhttps://www.mql5.com/ru/forum/131859/page6#comment_3359705

Только "Полезные функции от KimIV".
Только "Полезные функции от KimIV".
  • 2011.02.18
  • www.mql5.com
Все функции взяты из этой ветки - http://forum.mql4...
 
Is there any way to see what the resulting code will unfold into by applying macros?
 

A more specific and perhaps interesting question:

I use the same construct in different functions

if(FileReadStruct(handle,temp_rate)!=60)
{
  IsError=true;
  Print(__FUNCSIG__," Не удалось прочитать данные из файла по причине ошибки ",GetLastError());
  return;
}

However, some functions are void type and others return a value, so I return zero from them:

return(0);

Can I make a magic macro that substitutes the right one for me in each case?

 
Yurij Kozhevnikov:

A more specific and perhaps interesting question:

I use the same construct in different functions

However, some functions are void type and others return a value, so I return zero from them:

Can I make such a magic macro, which in each case would substitute for me the necessary variant?

Using return in a macro is a cocked gun pointed at its own leg, and when combined with if - it turns into a cannon))) But if you really want to:

#define  CHECK_READ(dHndl,dRate,dRet)  do \
if(FileReadStruct(dHndl,dRate)!=60){    \
  IsError=true;   \
  Print(__FUNCSIG__," Не удалось прочитать данные из файла по причине ошибки ",GetLastError()); \
  return dRet;} while(false)
  
...
CHECK_READ(handle,temp_rate,);
...
CHECK_READ(handle,temp_rate,0);
...

I haven't tested it, but it should work. Also turned the gun back into a pistol)))

 

Thank you!

So I pass in the last parameter either a value for return, or a blank, which will turn into

return ;

and a space means nothing. Of course, how did I forget that it can be used without my favourite brackets.

return(x);
return x; //равноценны

By the way, could you tell why this construct is inside a loop, which can be executed only once? Is it a gun, turned back into a gun? Are there possible situations like infinite recursion or something like that?

 
Yurij Kozhevnikov:

Thank you!

So I pass in the last parameter either a value for return, or a blank, which will turn into

and a space means nothing. Of course, how did I forget that it can also be used without my favourite brackets.

By the same token, can you tell me why this construct is stuffed inside a loop that can only be executed once? Is it a gun turned back into a gun? Possible situations like infinite recursion or something like that?

if (condition) CHECK_READ(h,r,0); else CHECK_READ(h,r,1);
Deploy the macro without the do-while wrapper and see what happens)))
 
Vladimir Simakov:
if (condition) CHECK_READ(h,r,0); else CHECK_READ(h,r,1);
Deploy the macro without the do-while wrapper and see what happens))
if (condition) if(FileReadStruct(h,r)!=60){   
  IsError=true;   
  Print(__FUNCSIG__," Не удалось прочитать данные из файла по причине ошибки ",GetLastError()); 
  return 0;}; else if(FileReadStruct(dHndl,dRate)!=60){    
  IsError=true;   
  Print(__FUNCSIG__," Не удалось прочитать данные из файла по причине ошибки ",GetLastError()); 
  return dRet;};

=

if (condition) 
 if(FileReadStruct(h,r)!=60)
 {   
  IsError=true;   
  Print(__FUNCSIG__," Не удалось прочитать данные из файла по причине ошибки ",GetLastError()); 
  return 0;
 }; 
 else 
  if(FileReadStruct(dHndl,dRate)!=60)
  {    
   IsError=true;   
   Print(__FUNCSIG__," Не удалось прочитать данные из файла по причине ошибки ",GetLastError()); 
   return dRet;
  };

That seems to be the case, if I understand the substitution principle correctly.

Extra semicolons after curly brackets. And it's not clear what else refers to now.

It's a pity there's apparently no easy way to automate macro expansion to see what happens. Unless you can make your own script.

Thank you! There is a reason there is no semicolon after while in the macro.

Reason: