Self-learning the MQL5 language from scratch - page 23

 
Aliaksandr Hryshyn:

You got off on the wrong foot. Do you understand everything in the code? All operators, keywords?

Check question on the code:

What do these lines mean?

These were my comments on the script:

/* Moving on. After sending requests to the trade server, we need to know if a pending order has been set
or not. To do this, let's use the OrderSend function which is designed for
trade operations by sending requests to the trade server. If sending a request to
fails (an exclamation mark in front of any function indicates a negative result of its execution
), then we output a message with an error code in the following format: "OrderSend error %d"
and GetLastError(). Let's understand what "OrderSend error %d" is and what GetLastError() is.
Note that "OrderSend error %d" is in double quotes. This means that
will print the text with the literal translation "OrderSend error %d". Now let's understand what
%d means. In the PrintFormat section of the MQL5 Reference, we find: "If a format string is followed by more parameters,
, this string must contain format specifications that define the format of outputting these parameters.
A format specification always starts with a percent sign (%)". What is a d? In the same section
just below we find: "Type d - specifies the minimum number of digits to be output. If the number of digits in
is less than the specified precision, the output value is padded with zeros on the left.
The output value is not truncated if the number of digits to be output is greater than the specified precision. With this
we have solved, now we need to understand what GetLastError() is. Again looking in the reference book: "GetLastError()
returns the content of the system variable _LastError, i.e., the variable in which
is stored the value of the last error that occurred during execution of the mql5 program.

Regards, Vladimir.

 
MrBrooklin:

So I haven't figured it out yet and there's work to be done.

Regards, Vladimir.

Again, start with the description of what your code does. This script puts the SL and TP on the positions. Since we don't know whether they are there, we assume that the positions are there, and there are both (hedge account). The condition of placing stops will always make true.... So it is like this. Work through the code to the end. ))))

And try to understand every line of the code. From the very beginning.

 
Реter Konow:
This condition is not needed there at all. What role does it play? Can you explain?

I wanted to set a hidden condition for setting pending Buy Stop and Sell Stop orders.

Regards, Vladimir.

Совершение сделок - Торговые операции - Справка по MetaTrader 5
Совершение сделок - Торговые операции - Справка по MetaTrader 5
  • www.metatrader5.com
Торговая деятельность в платформе связана с формированием и отсылкой рыночных и отложенных ордеров для исполнения брокером, а также с управлением текущими позициями путем их модификации или закрытия. Платформа позволяет удобно просматривать торговую историю на счете, настраивать оповещения о событиях на рынке и многое другое. Открытие позиций...
 
MrBrooklin:

Checked a few more times - the compiler doesn't give out anything.

Regards, Vladimir.

And why should it produce something? You don't know macros, you don't know how to work with them, but you use them, so you expect some error or at least a warning from them. If you had at least once launched your script on the demo and ran it in all modes, you would have seen that it didn't work. But you go further. You add a stop-loss, take-profit, and on the shore they say: "Stop the machine!

 
Valeriy Yastremskiy:

Again, start by describing what your code does. This script puts a SL and TP on the positions you have placed. Since we don't know if they are there, we assume that there are positions, and there are both (hedge account). The condition of placing stops will always make true.... So it is like this. Work through the code to the end. ))))

And try to understand every line of the code. From the very beginning.

Thanks for the tip about checking if there are any open positions at first.

Regards, Vladimir.

 
MrBrooklin:

I wanted to set a hidden condition for setting pending Buy Stop and Sell Stop orders.

Sincerely, Vladimir.

Tell me, is writing a macro for that, is it the only way to set such a condition? The conditions, as I understand it, are set only by macros? Or you can do it in some other way? And if there is another way, why did you choose this macro? There must have been some necessity? But what was it?

 
MrBrooklin:

Thanks for the tip about checking if there are any open positions first.

Regards, Vladimir.

Don't even try it now. It's too early to do it. It's too early. You'll get mushy, you'll get tired, and you'll give it all up. Go back to the textbook and simple problems.
 
Vasiliy Sokolov:

Is writing a macro for this the only way to set this condition? As I understand it, conditions are only set by macros? Or is there some other way? And if there is another way, why did you choose the macro? There must have been some necessity? But what was it?

No, there was no necessity, I simply found #define when studying modifiers and decided to try it in the script.

Sincerely, Vladimir.

 
MrBrooklin:

I wanted to set a hidden condition for setting pending Buy Stop and Sell Stop orders.

Regards, Vladimir.

What does "hidden condition" mean? This type of conditions does not exist in programming.
 
Vasiliy Sokolov:

... If you'd run your script on a demo for once and run it in all modes, you'd see that it doesn't work. But you're taking it a step further. You add a stop loss and take profit, and the shore is already shouting: "Stop the car!"

Vasiliy, I ran the script more than once and all modes work, namely, I put two pending orders Buy Stop and Sell Stop at the distance I specified. Stop Loss and Take Profit are also set at the needed distance. The orders work. I would like to attach a screenshot here.

Regards, Vladimir.