Self-learning the MQL5 language from scratch - page 15

 
Vasiliy Sokolov:

Programmers have two problems: compiler errors and architecture problems. While you are a beginner, you focus on fighting the compiler, and your ultimate goal is a program that works correctly. However, very quickly a beginner's program turns into so-called spaghetti code, which the author himself can't figure out soon enough. That's why I suggest that you focus not on the compiler and correctness of the final script but on architectural issues. It is like learning to play the piano: first you learn how to hold fingers correctly and sit at the instrument properly, no one demands playing Bach from a beginner.

You have two groups of parameters which determine the behavior of your script: the first is set statically, as a macro. The second is set by the user when loading the script on the chart. Now the user will not be able to select the type of the order to be placed without recompiling this script. This is not good. Therefore, it would be better to abandon these macros in favor of the additional parameter:

Accordingly, we have defined a new enumeration, which we have implemented as a selection parameter for the user.

Now I laughed seeing your style, also with specific errors, scribble some more.

 
MrBrooklin:

Hello, Peter! I study the textbook as needed, i.e. when I see a gap in my knowledge. Now, I feel that I will have to take a little pause and study the textbook more closely. All recommendations from forum participants are taken into account and I'm trying to stick to them. And now I'm amazed that I have managed to write something using only MQL5 Reference book for such a short time.

Regards, Vladimir.

The MQL4 Reference book by Kovalev is the best one. It's available somewhere on this site. You won't find a better one.
 
Vasiliy Sokolov:

The next problem with your code is that it sprawls out into a long procedural sheet. All beginners write this way. And this is a problem that stays with them for years. Learn to break your algorithm into parts, starting from the basics like this script. There are two ways to do this: through functions and classes. The concept of classes is too difficult to grasp at first, so I suggest you focus on working with functions...why not write one yourself?

The main thing that a function gives you is the ability to think structurally and sketch out an algorithm schematically. For example, if there was a special set of functions you needed in MQL for your task, you could write a very simple algorithm:

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()                                                    
  {
   if(orderType1=="BUY_STOP")
     SendBuyStop(Lots, Distance);     
   if(orderType2=="SELL_STOP")
     SendSellStop(Lots, Distance);
  }
  

And that's it. We have a simple algorithm scheme before our eyes, which also works. A dream in a word.

 
Roman:

Now I laughed when I saw your style, and with specific mistakes, scribble some more.

What do you have to do with mistakes, you don't even know how for works, but you're giving out advice. Have been put on the spot actually, no offence)

 
Реter Konow:
Note that the MQL4 tutorial by Kovalev is the best. It is available somewhere on this site. You won't find a better one.

It's just plain old stuff that no one needs these days. It's better to read Kafka before going to bed. It's more useful.

 

Here, the best way to start learning an applied language for highly specialised tasks, without getting confused by amateurs' advice or breaking your head over ill-timed tasks:

Sergei Kovalev's textbookhttps://book.mql4.com/ru

Учебник по MQL4
Учебник по MQL4
  • book.mql4.com
В настоящее время персональный компьютер стал незаменимым помощником в жизни каждого человека. Благодаря развитию Интернета и увеличению мощности современных компьютеров открылись новые возможности во многих областях деятельности. Ещё десять лет назад торговля на финансовых рынках была доступна только банкам и узкому кругу специалистов. Сегодня...
 
Vasiliy Sokolov:

You don't even know how it works, but you're giving out advice. (You've been put on the spot, no offence taken)

Oh ho ho ho ))

There are other people giving out advice here.
The problem was asked for condition for, no one answered it, including you!
What place, can be talking about, if I see the opposite picture))

 
Vasiliy Sokolov:

It's just plain old stuff that no one needs these days. It's better to read Kafka before going to bed. It's more useful.

What do you mean, old stuff? An alphabet, an ABC book, could it be junk? Maybe arithmetic is old?

You are a good programmer, but as a teacher you do not see the information that is relevant to your student and you misjudge his level. He has to master the basics in the right order, and only a good textbook helps).

 
Реter Konow:
Vasily, the man hasn't even mastered arrays yet. It's too early for him to listen to such lectures).

Peter, let's not. Let's remember how we explained OOP to you at the forum a few years ago).

Well, the truth is, not even all modern programmers understand what an array is. Everyone works with lists, and not every language has an array inside. Somewhere it is enumerator + map, for example, and the public doesn't complain.

 
Vasiliy Sokolov:

Peter, let's not. Let's remember how we explained OOP to you at the forum a few years ago).

Well, the truth is, not even all modern programmers understand what an array is. Everyone works with lists, and not every language has an array inside. Somewhere it is enumerator + map, for example, and the public doesn't complain.

No, you are too much.))) (I remembered that we are on a first-name basis. It's been a long time since you were here:))

Everyone should know arrays!))), but OOP is not required. It's good of course, but it's too early to talk about it.
Reason: