Discussion of article "Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator" - page 3

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Question 4: The article states the following:
But why do we put zero into the request.tp structure element? Because if we have a pending buy order , request.tp=0 means that TP will always be below the current Bid price. And, as it seems to me, an order with such a TP value should either be rejected because of the incorrectly specified value of the TP parameter, or should be immediately executed at the current Bid price after the server accepts such an order.
Question 5: The article states the following:
The MQL5 Reference Manual also states that"SYMBOL_TRADE_STOPS_LEVEL is the Minimum margin in pips from the current closing price for setting Stop orders". As it seems to me, in both cases it is a matter of fulfilment of the inequality
Why then does the Expert Advisor code check the distance between Bid (Ask) and StopLoss for exceeding the minimum StopLevel indentation?
Is such a check necessary in all cases, or is it a peculiarity of implementation of a particular strategy? In short, should I always check the distance between Bid (Ask) and StopLoss when placing a pending order to see if the minimum StopLevel margin is exceeded?
But why do we put zero in the structure element request.tp? Because if we have a pending buy order , then request.tp=0 means that TP will always be below the current Bid price. And, as it seems to me, an order with such a TP value should either be rejected due to an incorrectly specified value of the TP parameter, or should be immediately executed at the current Bid price after the server accepts such an order.
In short, should I always check the distance between Bid (Ask) and StopLoss when placing a pending order to see if the minimum StopLevel margin is exceeded?
It is always necessary to check the SL/TP/Entry price level of pending orders for the minimum margin in cases when you work with setting orders very close to the market.
If you work with stops or pending orders in a reasonable and remote from the market mode (tens and hundreds of points), you can skip such a check.
You should always check the SL/TP/Entry price level of pending orders for minimum indentation in cases when you work with setting orders very close to the market.
Clarifying question 5.1.
I have the Expert Advisor calculate three levels for each pending order: Entry price/SL/TP.
Since it is not known in advance how close/far the Entry price level will be located relative to the current market price, checking the Entry price level for compliance with the minimum margin does not raise any questions.
But what level should we check the remaining two SL/TP levels against? It is somewhat illogical to check SL/TP levels relative to the current market price, because the Entry price level can be located quite far from the current market price, and such a check loses all relevance. That's why I provided for checking the condition |Entry price-TP(SL)|>SYMBOL_TRADE_STOPS_LEVEL in the Expert Advisor. In general, the Expert Advisor works fine with such conditions, but when I started optimising the EA code, I wondered whether such a check is necessary from the point of view of pending order processing by the server. The EA code is not overloaded by checking this condition (the EA strategy itself does not require such a check).
In other words, should the pending order with three Entry price/SL/TP levels always check the SL/TP levels for the minimum margin? And if so, should it be checked for a minimum margin relative to which level (price)?
Something is missing the ability to edit my post. So I will add here:
= For each pending order, the Expert Advisor calculates three levels independently: Entry price/SL/TP. The purpose of "setting a pending order closer to the market" is not pursued. =
SL and TP in the pending level are evaluated from Entry price so that they are not less than a minimum level away from it.
It works the same way in MT4.
SL and TP in the pending level are evaluated from the Entry price so that they are at least a minimum level away from it.
It works the same way in MT4.
OK, now I understand everything. So, I can't make the EA code easier; initially everything was done in accordance with the article, i.e. correctly.
And I am not familiar with MT4, so such questions are "from a dummy". Thank you!
...Always check the SL/TP/Entry price level of pending orders for the minimum indentation in cases when there is work with setting orders very close to the market.
...SL and TP in the pending level are estimated from Entry price so that they are not less than a minimum level away from it.
Question 6: It is clear with checking the minimum indentation when placing pending orders. Now we have a question about the peculiarities of checking the minimum margin when modifying the TP/SL of an open position.
Situation: an open position has a fixed TP and a "pull-up" SL, which approaches the fixed TP as the price moves in a favourable direction. By analogy with setting a pending order, each time the Expert Advisor sends an order to modify the TP/SL of an open position, it checks the minimum indentation with respect to both TP and SL levels.
But in the description of the PositionModify function from the CTrade class it is specified that the tp parameter is "The new price at which Take Profit will be triggered (or, if the change is not necessary, the previous value)".
Accordingly, the question is: if a change of the previously set TP level is not required, when sending an order to modify the TP/SL of an open position, is it necessary to check the minimum margin of this TP level from the current (actual) price? Or in such a situation is it enough to check the minimum margin only in relation to the modifying SL?
In other words, when sending an order to modify the TP/SL of an open position, is it possible not to check the minimum margin in relation to TP, if this TP level has already been set earlier and is not subject to change? And in the order for modification just specify the previous TP value?
After downloading the file "indicator_TP_en.mql5", rename it to "indicator_TP.mql5", please.