Discussion of article "Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator"
Happy Victory Day!
Could you please advise me?
The Expert Advisor contains a cycle of alternate search of all open positions. PositionGetDouble(POSITION_SL) function is used in the cycle. It follows from the description of the POSITION_SL parameter that it can be used to get theStop Loss level for an open position.
Question 1: what value will the PositionGetDouble(POSITION_SL) function show if an open position was formed as a result of triggering several pending orders with different Stop Loss levels?
Question 2: if an open position was formed as a result of triggering several pending orders with different stop-loss levels, what is the best way to get data on these stop-loss levels?
If this topic has been discussed before, please provide a link.

- www.mql5.com
Happy Victory Day!
Question 1: what value will the PositionGetDouble(POSITION_SL) function show if an open position was formed as a result of triggering several pending orders with different stop-loss levels?have you checked what the function returns?
No, I haven't. Because I don't know all the important initial conditions that must be observed when checking (testing) a particular function. And also because of my negative attitude to the possibility of using the scientific poke method when learning a programming language new to me.
Explanation. The very small number of articles dedicated to Expert Advisors and the absence of a textbook on MQL5 forces the average user to rely on the materials available on the web, including this (and very useful) article, when implementing his own trading strategy.
As you understand very well, my questions concern theoretical and applied aspects that are not reflected in the current version of the MQL5 Reference Guide, as well as in the available articles on MQL5 Expert Advisors.
Under such circumstances, I think it is much more reasonable to ask knowledgeable people (language developers and authors of articles) questions on certain theoretical-applied aspects of MQL5 functions, instead of conducting experiments, "checking what a function returns" under certain conditions, and similar amateurishness.
Agree that an answer from knowledgeable people about "what should be" looks more optimal than a counter-question like "have you checked what the function returns" (in the absence of my understanding of the peculiarities of its functioning).
Found the answer. In the Client Terminal User's Guide:
...Уровни Тейк Профит и Стоп Лосс устанавливаются для позиции по последнему ордеру (рыночному или сработавшему отложенному).
Иными словами, стоп уровни в каждом последующем ордере по одной позиции заменяют предыдущие.
...Срабатывание ордеров Тейк профит и Стоп Лосс приводит к полному закрытию позиции.
Strange. Since only one open position is possible for each financial instrument, it turns out that scenarios with partial closing of a position by stop-loss cannot be implemented in principle?
P.S. After finding out this peculiarity inherent in MT5, there is no need to check the value returned by the PositionGetDouble(POSITION_SL) function if an open position was formed as a result of triggering several pending orders with different stop-loss levels.
Found the answer. In the User Manual of the client terminal:
Strange. Since only one open position is possible for each financial instrument, it turns out that scenarios with partial closing of a position by stop loss cannot be implemented in principle?
P.S. After finding out this peculiarity inherent in MT5, there is no need to check what value the PositionGetDouble(POSITION_SL) function returns, if an open position was formed as a result of triggering several pending orders with different stop-loss levels.
it is possible to make in the form of the function "izpodvypodvert vypert vypert podvypert" which will split take profit according to the volume of transactions on the given instrument into pending orders by levels.
but personally I consider this function unnecessary as I am familiar with official trading terminals where there is no locking.
can be made as a function "from-sub-sub-sub-sub-sub-sub-sub-sub-sub-sub-sub-sub-sub-sub-sub-sub-sub-sub-sub" ...
Yes, I've already scratched my head on this topic. There are three options :)
- either to creatively rework existing scenarios for MT5 peculiarities;
- or create a class of sub-sub-sub-sub-sub-sub-sub-sub-sub-sub-sub-sub-sub functions;
- or avoid using stop-losses and take-profits in orders, initially operating instead with bundles of orders of the opposite direction.
Never mind, we'll get through it! :)
Question about placement of ArraySetAsSeries functions in the Expert Advisor.
ArraySetAsSeries functions are placed in OnTick() function right after CopyTime, CopyHigh and CopyLow functions.
Are there any obstacles to placing ArraySetAsSeries functions in the OnInit() function, or should arrays always be indexed only after they are copied?

- www.mql5.com
Question regarding the placement of ArraySetAsSeries functions in the EA.
ArraySetAsSeries functions are placed in OnTick() function right after CopyTime, CopyHigh and CopyLow functions.
Are there any obstacles to placing ArraySetAsSeries functions in the OnInit() function, or should arrays always be indexed only after they are copied?
For indicator buffers, it says SetIndexBuffer:
Note
After linking, the dynamic array buffer[] will be indexed as in regular arrays, even if the array being linked is pre-set to be indexed as in timeseries. If it is necessary to change the order of access to the elements of the indicator array, it is necessary to apply the ArraySetAsSeries() function after binding the array with the SetIndexBuffer() function.It should be similar for Expert Advisors, check

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
New article Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator is published:
MetaQuotes Programming Language 5 (MQL5), included in MetaTrader 5 Client Terminal, has many new possibilities and higher performance, compared to MQL4. This article will help you to get acquainted with this new programming language. The simple examples of how to write an Expert Advisor and Custom Indicator are presented in this article. We will also consider some details of MQL5 language, that are necessary to understand these examples.
Author: Denis