Self-learning the MQL5 language from scratch - page 64

 
MrBrooklin:

Does Alert() have to be used, or is it just for information?

Not necessarily, it is just for convenience

 
VVT:

Not necessarily, it's for convenience

I see.

Respectfully, Vladimir.

 
MrBrooklin:

Hello Valery! Thank you for your advice. I've already made some friends with the if-else operator, and now I need to master the switch operator as well. Do I need to use Alert() or is it just there for more information?

Regards, Vladimir.

In the light of my experience as an electronics engineer. When there is a fire, a siren, when the floor is not cleaned, a note to the cleaner. Comment writes on the chart, print to log, wright to file, alert beeps, and there is also a message box, also beeps, but it is not native.

 
Valeriy Yastremskiy:

In view of the experience of the electrician. On fire siren, on floors not cleaned, remark to cleaner. Comment writes on chart, print to log, wright to file, alert beeps, and messege box is also beeping, but that's not native.

Thank you, you've explained it very well!

Regards, Vladimir.

 
Valeriy Yastremskiy:

If positions with our Magik and on our symbol are zero, we check the time and open a position, if it is 1, we don't open a position, we check the closing time and trawl, if it is more than 1, we alert and don't work. We may use scrolls or check iff.

Hello Valery! Thanks a lot, your version "... if positions with our magik and at our symbol are equal to zero, we check the time and open a position..." turned out to be the simplest and most effective. I added it to the condition of checking time && PositionTotal()==0 and only one position with the needed amount is opened!

   if(time_current.hour==time_open.hour && time_current.min==time_open.min && PositionsTotal()==0)
      OpenBUY();

Sincerely, Vladimir.


 
Here's an interesting article
https://www.mql5.com/ru/articles/35

Exp and indicator.
 
Aleksey Masterov:
Here's an interesting article
https://www.mql5.com/ru/articles/35

Exp and indicator.

Hi Alexey, thanks for the link to the article. Yes, there is a lot of interesting stuff in it.

Regards, Vladimir.

 
MrBrooklin:
if(time_current.hour==time_open.hour && time_current.min==time_open.min


this is not the best way to compare the waiting time to open a position

in the tester everything will always work smoothly, in the real account errors may occur - the expert advisor works upon the arrival of a tick, if for some reason the tick does not come exactly at the minute you are waiting for it, your algorithm will not work correctly and it will be very hard to find this logical error later


try to reformulate this problem to get away from strict equality comparison ( == ) to condition more or equal ( >= ) ....( and/or condition less or equal)

 
Igor Makanu:

this is not the best way to compare the waiting time to open a position

in the tester everything will always work smoothly, in the real account errors may occur - the expert advisor works upon the arrival of a tick, if for some reason the tick does not come exactly at the minute you are waiting for it, your algorithm will not work correctly and it will be very hard to find this logical error later

try to reformulate the problem to get away from strict equality comparison ( == ) to a condition greater than or equal to ( >= ) ....( and/or less than equal condition)

Hi Igor, thanks for the tip. Completely agree with your reasoning, as tick situations can indeed be different. I will make a correction in the code.

Regards, Vladimir.

 

Corrected the code, as recommended by Igor. Very good and timely tip! It eliminated a problem in the EA operation, which I had not noticed before. Thank you again Igor!

Sincerely yours, Vladimir.