Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1744

 
Please tell me, mql5, an Expert Advisor sometimes needs to write a time value to read it, but there may be a crash, etc. and the time will be erased. Can I write datetime in a global variable in the terminal, but it is double, no problems? Thank you!
 
Fast235 #:

Help for the pros, it's quicker to ask, namely to hire a tutor so to speak. believe me, it's cheaper and quicker.

but you need an enthusiastic professional to tutor, not just a deep pro, you need to explain the base correctly and that's it. the other 10k pages. heterogeneous information....

Thanks for the advice!

 

Can you tell me which is better:

Write everything in one OnTick block or separate it by function? That is, to have only function calls in OnTick

(my question is mostly about code optimization and any prospects and pitfalls)
 
freelancerAntonyan global variable in the terminal, but it is double, no problems? Thank you!
Nothing will be written in case of a crash, GV as well. And in principle there are no problems. Just apply an explicit type conversion when writing and when reading too.
 
freelancerAntonyan global variable in the terminal, but it is double, no problems, or some other way is better? Thank you!

any type can be written to and read back from double via union.

 
Ivan Butko function calls in OnTick(The question is mostly about code optimization and any perspectives and pitfalls)

Function calls are more correct.

Only functions should be logically complete and understandable, so that you can understand the logic of OnTick from the code.

 
MakarFX #:
Give me the file here. This is something new, I haven't heard that yet.

Rename any *.mq4 file to any extension and try to compile it, it won't work, the compiler will try to compile it as if it were MT5.

Whatever I wrote there inside file, like(

#ifdef __MQL4__

#else

#endif

does not work until I rename the file back to *.mq4.

How to bypass it, may someone from the pros know?

 
Valeriy Yastremskiy #:

Function calls are more correct.

Only the functions should be logically complete and understandable, so that you can understand the logic of the operation in OnTick from the code.

Thank you, I mean
 
Sergey Zhukov #:

Rename any *.mq4 file to any extension and try to compile it, it won't work, the compiler will try to compile it as if it were MT5.

Whatever I wrote there inside file, like(

does not work until I rename the file back to *.mq4.

How do I get around it, can someone from the pros know?

It doesn't compile at all!

Throw the file. you can remove all the functions inside

 
Sergey Zhukov #:

Rename any *.mq4 file

Sergey, not quite sure why to rename the file, but it works this way:


include1.mqh:

void go()
   {
   #ifdef __MQL5__
      printf("Это пятёрка");
   #else
      printf("Это четвёрка");
   #endif
   }

script1.mq4 and script1.mq5:

#include <include1.mqh>

void OnStart()
   {
   go();
   }


Got it, that's the problem:

__MQL4__

there is no such thing in the language now.

Reason: