Self-learning the MQL5 language from scratch - page 47

 

Vladimir Simakov:

My mate looked at this shit and said: 250 grand for me and 75 grand each for my two junks, and we'll rewrite this shit in six months or get rid of it.

this is the right decision judging by the set-up, with the approach described there will always be problems with the GPs.

 
MrBrooklin:

I read all the posts about global variables and understood what all the participants in this discussion were trying to tell me. I will learn how to write program code without using global variables. Thank you all for this constructive advice!

Sincerely, Vladimir.

Programmers are afraid to use global variables because of the mistakes that can be made when changing their values. It creates a situation when an error is difficult to localize, because each function can change them. Of course, only those variables must exist in the global scope which all the program functions must see. It cannot be otherwise.

I always liked using global variables, because they ensured fast growth of functionality, and the program turned into a huge, active construction site. People often blame me for the way I write code, but that's why it's a construction site: you clean it up after the basic building work is done, and when the house is finished, you can start tiling, painting, cleaning up the area. Until then, the priority is to assemble the formwork and pour concrete).

However, programmers think differently. They will 'clean' and 'scrub' their code, even if it is two and a half lines. They will scrub their code even if it is two and a half lines long, but it will shine like a new coin.) This attitude to code is justified by their profession which they live by, but from the creative viewpoint, they are stiff and poorly developed. That's the way it is...

My advice: learn to write properly, but sometimes allow yourself to move away from the rules and experiment to gain a more varied experience. This will help with your learning and you will learn more quickly.
 
MrBrooklin:

I continue studying the MQL5 programming language. I am pasting the revised code of the script again, taking into account the tips from the participants of this thread. I have tested the script in all modes. No problems detected. To begin with I have applied the minimum number of input parameters. The script code is written in English, comments to the code are in Russian, so that it is easier to digest. As I promised earlier, I tried to describe the script in a way understandable for a 1st class student of the programming school.

I hope I did it the way I was told by the participants of this thread, but I could be wrong.

Regards, Vladimir.

It's great that you have figured out how and where to move the global variable bool enough_time yourself. You are making progress.
 
Реter Konow:
It's great that you have figured out how and where to move the global variable bool_timе. You are doing a great job.

Thank you, Peter, for your support and help. I moved the global variables inside the function thanks to the tips that were given to me earlier by the participants of this thread. Now, when the information is sorted out in my head, it becomes much easier to grasp the new things.

Regards, Vladimir.

 

Good morning everyone and good mood!

Dear programming experts! I would like to express my sincere gratitude for all hints and constructive advice, which you share with me!

Sincerely, Vladimir.

 
MrBrooklin:

Good morning everyone and good mood!

Dear programming experts! I would like to express my sincere gratitude for all hints and constructive advice, which you share with me!

Sincerely, Vladimir.


You are fast moving ... :-)
It's because of my basic higher technical education, if I'm not mistaken...

 
Aleksey Masterov:

You're moving fast... :-)
It's because of a basic higher technical education, if I'm not mistaken...

Hello Alexey! Yes, that's right, I have a soviet higher technical education connected with automation of processes in production and experience as an electronic engineer in an organization which was engaged, in those same soviet times, in repairing ECMs.

Regards, Vladimir

 
MrBrooklin:

Hello Alexey! Yes, that's right, I have higher technical education connected with automation of processes in production and work experience as an electronic engineer in the organisation which was engaged, in the same Soviet times, in repair of ECM.

Sincerely, Vladimir.


It is immediately noticeable at you, for me... At the level and speed of your progress in this "art" of translation of fantasies into code, especially such philosophical ones as in your latest script! :-)
IMHO, if you continue at this rate, you'll rub the noses of many a la progam experts here ... :-)
Apply for a remote job with the MT5 methaquotes team!!!
 
Vasiliy Sokolov:

Continued at

It was clear from the post above that the focus was on functions. Everything was devoted to them and nothing but them. One might think that this is an obvious subjective bias or some arcane "philosophy". However, there is no philosophy here. And such attention to functions is not accidental. The point is that in programming, function is of fundamental importance. Moreover, the function is a very important and fundamental notion in mathematics. In the 20s of the last century, Alonzo Church developed a system of calculus based on functions. This was called lambda-calculus. This system formalized the notion of calculability and tightly bound computer calculations and mathematics. The leading programmers of the world developed so-called functional programming languages based on lambda-calculus, in which functions take the leading place. For example, in a functional Haskell programming language, there is not even a for loop or something similar. Instead, it is proposed to call a function in a special way, recursively, to calculate the desired value. It can be proven that with only functions and no assignment, it is possible to write a Turing complete programming language. This is a language that would allow to write everything that is possible in any other turing-complete language, such as procedural or OOP language.

MQL is not a functional language, but rather a procedural one, extensible by classes, with strict typing and rich subject-oriented API (in the form of the same functions, oh surprise). On the other hand, the theory of functions is based on a solid mathematical foundation, offers simple and effective patterns of using any programming language where there are functions, so it is at least not far-sighted to abandon functions and mathematical basis behind them. This is why I pay so much attention to functions. It doesn't matter how well you understand the array design, or if you make a mistake with a certain data type. This can be quickly fixed and corrected. But if you don't understand functions and how they are related, you won't even become an average programmer.

Thus, to learn how to normally prog, ie linearly over time to expand the functionality of your program, you need to learn the following:

  • Clearly (if not thoroughly, but clearly need to) represent the event model of MetaTrader 4.5.
  • Know how to work with the system functions. Summarize their results in their own functions. Combine the calls of system functions into your own functions.
  • Being able and fond of writing your own functions.
  • Be able to understand function call chains: e.g. when function a() calls function b(), and b() calls c() and e() calls function c().
  • Know how to write clean functions and understand why you should write clean functions. I will explain what a pure function is later.

Functions seem simple. "What's there to learn. You just need to read a paragraph here, and that's all. And then arrays, for, while..." - No, they're not. Functions do seem simple (and that's fine). But for them to really solve tasks efficiently, functions must have certain properties and be combined with each other in a certain way. How to do all this I will probably write later.

Hello Vasiliy! Please, if it is not difficult for you, write a sequel about function properties. For me, as for other novices in programming, it is very important and useful to know that functions must have certain properties and join each other in a certain way.

All your message blocks relating to functions are already collected for me in a single Wordboard file.

Sincerely, Vladimir.

 
Aleksey Masterov:

... Apply for a remote job with the MT5 methaquotes team!!!

Alexei, are you kidding? Yes, I'd like to learn the basics first!

Sincerely, Vladimir.