Self-learning the MQL5 language from scratch - page 57

 
MrBrooklin:

I continue learning the MQL5 programming language. Previously I published the code of the loop that starts the enumeration of open positions. Now, after the loop has been started, we start working with the symbol on the current chart:

I will periodically post the written code with my own comments for providing a prompt feedback. I am asking the participants of this topic to correct me, if there are any inaccuracies in my codes and comments.

Sincerely, Vladimir.

Print("Выбираем позицию на символе ", PositionGetSymbol(i), "Тикет", i);

Comments containing data are more practical.

 
Valeriy Yastremskiy:

Comments containing data are more practical.

Thank you, Valery! Your version of the message is more informative. I will change the code at once.

Regards, Vladimir.

 

Dear programming experts!

Please explain two questions:

  1. First question about Magic Number - is it created in input parameters only for pending orders and open positions (or only for open positions?), or for the EA itself it can be created too? If the answer is "yes," for what purpose should this be done. I have really got confused with this question and do not have a good answer.
  2. The second question about Magic Number - if there is more than one open position in the current chart, then it is possible to apply such an input parameter to determine each position:
input int Magic_Number=-1;

Maybe I have a wrong understanding of Magic Number application in programming at all.

Regards, Vladimir.

 

Although there is an explanation in Artem Trishkin's article https://www.mql5.com/ru/articles/7394#node02, but I still don't understand it, because he makes it too complicated.

Sincerely, Vladimir.

 
MrBrooklin:

Dear programming experts!

Please explain two questions:

  1. First question about Magic Number - is it created in input parameters only for pending orders and open positions (or only for open positions?), or for the EA itself it can be created too? If the answer is "yes," for what purpose should this be done. I have really got confused with this question and do not have a good answer.
  2. The second question about Magic Number - if there is more than one open position in the current chart, then it is possible to apply such an input parameter to determine each position:

Perhaps I have a wrong understanding of Magic Number application in programming at all.

Sincerely, Vladimir.

Why do you need Magic Number now? Really, what's the point of bothering with it now? The trailing stop will obviously be used as an element of semi-automatic trading: someone has placed an order, and the EA starts trawling through it. Who cares who placed the order? If another robot has placed it, and you open a trawl, your Expert Advisor will also trawl his or her order. If you do not set the trawl, it will not. This is exactly the case when you do not need a magik. If you suddenly need it later, you can write it later.

 
MrBrooklin:

Although there is an explanation in Artem Trishkin's article https://www.mql5.com/ru/articles/7394#node02, but I still don't understand it, because he makes it too complicated.

Sincerely, Vladimir.

You definitely don't need to read this.

 
MrBrooklin:

Continuing to learn the MQL5 programming language. Previously I published the code of the loop that starts the enumeration of open positions. Now, after the loop has been started, we start working with the symbol on the current chart:

I will periodically post the written code with my own comments for providing a prompt feedback. I ask the participants of this topic to correct me, if there are any inaccuracies in my code or comments.

Sincerely, Vladimir.

Again you are starting with a wrong idea and the code contains an error. Start with the functions. Write a framework of the algorithm using only your own functions. Then we will think how to implement them. Start with the standard template that is opened when creating a new EA in metaeditor.

The trailing stop is better to be made for the net account to begin with. This way it will be easier to work with the position, because there will only be one position for a symbol. In the second version, it will be possible to change it into a hybrid.

 
Vasiliy Sokolov:

Why do you need Magic now? Really, what is the point of bothering with it now? The trailing stop will obviously be used as an element of semi-automatic trading: someone places an order, and the EA starts trawling through it. Who cares who placed the order? If another robot has placed it, and you open a trawl, your Expert Advisor will also trawl his or her order. If you do not trigger a trawl, it will not. This is exactly the case when you do not need a magik. If you suddenly need it, please, write it down later.

Hello Vasily! I understand everything about the Magic Number, but the problem is that it was strongly recommended to me by Andrey Novichkov here.

Regards, Vladimir.

 
Vasiliy Sokolov:

You definitely don't need to read this one.

I see.

Respectfully, Vladimir.

 
Vasiliy Sokolov:

You are starting from the wrong place again, and the code contains an error. Start with the functions. Write the algorithm framework using only your own functions. Then we will think how to implement them. Start with the standard template that is opened when creating a new EA in metaeditor.

The trailing stop is better to be made for the net account to begin with. This way it will be easier to work with the position, because there will only be one position for a symbol. In the second version, it will be possible to convert it into a hybrid.

The standard template was created. I started writing the code in it and will post those fragments that have already been written here. I hadn't guessed about the algorithm framework with my own functions, thanks for the tip! Also thanks for the tip about the netting account!

If it's no secret, what's the error in the code?

If it's here:

 for(i; i>=0; i--)

I've already corrected it to:

 for(i; i>0; i--)

Sincerely, Vladimir.

Reason: