Leo59: Thanks! As I understand it, the concept of "active order" includes BUY and/or SELL positions, as well as pending orders set (accepted by broker). If I have: Long and Short positions opened, and Buy Limit and Sell Stop set, then OrdersTotal() will return value =4. Right?
There may be an open BUY position and an active BUY order. I gave an example of code above, but perhaps it is easier to explain it in figures. How the TP of an open position triggers
The price reaches the TP of the BUY position.
The trade server creates a corresponding active SELL order.
Thereafter, the terminal has simultaneously a BUY position and a SELL order.
The SELL order is executed by getting into history and generating a deal there.
The initial BUY position is closed on the basis of the deal data, but it does not get anywhere - it is indirectly present in the deal history.
Leo59: Everything has long been accepted, and before writing documentation, it would probably be worthwhile to read Sergei Kovalev's tutorial (it's built into MQL4):
Read the name of this branch. Everyone thought it was MQL5. There is a corresponding section for MQL4 and MT4 here on the Forum. If you asked your question there, the answer would be different.
Leo59: Everything is already taken care of, and before writing the documentation, it would probably be worthwhile to read Sergei Kovalev's tutorial (it is built into MQL4):
This is how a block can be constructed in which market and pending orders are analyzed:
for (int i=1; i<=OrdersTotal(); i++) //Цикл по всем ордерам,.. { //отражённым в терминале if(OrderSelect(i-1,SELECT_BY_POS)==true)//Если есть следующий { // Здесь должен выполняться .. // ..анализ характеристик ордеров } } //Конец тела цикла
The loop statement header contains the initial value i=1, and the condition for the loop termination is the expression i<=OrdersTotal(). Function OrdersTotal() returns the total amount of market and pending orders, i.e. those orders that are reflected in the Terminal on the Trade tab. Therefore, the number of iterations in the loop will be the number of orders present in the trade.
Please insert code correctly:Correctly insert code on the forum(I've already corrected what you inserted - and look: you inserted just text, and now it's CODE, with syntax highlighting).
Leo59: Everything is already taken care of, and before writing the documentation, it would probably be worthwhile to read Sergei Kovalev's tutorial (it is built into MQL4):
This is how a block can be constructed in which market and pending orders are analyzed:
for (int i=1; i<=OrdersTotal(); i++) //Цикл по всем ордерам,.. { //отражённым в терминале if(OrderSelect(i-1,SELECT_BY_POS)==true)//Если есть следующий { // Здесь должен выполняться .. // ..анализ характеристик ордеров } } //Конец тела цикла
The loop statement header contains the initial value i=1, and the condition for the loop termination is the expression i<=OrdersTotal(). Function OrdersTotal() returns the total amount of market and pending orders, i.e. those orders that are reflected in the Terminal on the Trade tab. Therefore, the number of iterations in the loop will be the number of orders present in the trade.
Not only you are talking about mql4 and have shown a code from mql4 (and this thread is about the features and subtleties of programming in mql5), but you've also written the loop incorrectly - you have to start from zero, otherwise you will always miss one order.
... I don't have any problems with mt4, and it has no division of orders and positions - it's all mixed together
In MQL5, the function OrdersTotal() will return the number of pending orders. So, in MQL5, everything is systematized at a higher level: cutlets separated, flies separated.
As for the trading functions - there are differences. I've already mentioned above about MQL4:
whereas in MQL5 OrdersTotal() will return the number of pending orders. Thus, in MQL5 everything is systematized at a higher level: cutlets separated, flies separated.
One should not confuse between active pending orders and positions, which are also displayed in the "Trade" tab of the "Toolbox" panel. An order is an order to conduct a trade operation, and a position is the result of one or more trades.
With "netting" of positions (ACCOUNT_MARGIN_MODE_RETAIL_NETTING and ACCOUNT_MARGIN_MODE_EXCHANGE) only one position can be opened for each symbol at any given time and it is the result of one or more deals. Positions and active pending orders, which are also displayed in the "Trade" tab of the "Toolbox" panel, should not be confused with each other.
When the positions are presented independently (ACCOUNT_MARGIN_MODE_RETAIL_HEDGING), several positions can be opened for each symbol simultaneously.
PositionsTotal()
It returns the number of open positions.
intPositionsTotal();
Returned value
Value of the int type.
Note
With "netting" positions (ACCOUNT_MARGIN_MODE_RETAIL_NETTING and ACCOUNT_MARGIN_MODE_EXCHANGE) only one position can be opened for each symbol at any moment and that is the result of one or more trades. Positions and active pending orders, which are also displayed in the "Trade" tab of the "Toolbox" panel, should not be confused with each other.
In the independent representation of positions (ACCOUNT_MARGIN_MODE_RETAIL_HEDGING), several positions can be opened for each symbol simultaneously.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Thanks!
As I understand it, the concept of "active order" includes BUY and/or SELL positions, as well as pending orders set (accepted by broker).
If I have: Long and Short positions opened, and Buy Limit and Sell Stop set, then OrdersTotal() will return value =4. Right?
There may be an open BUY position and an active BUY order. I gave an example of code above, but perhaps it is easier to explain it in figures. How the TP of an open position triggers
Everything has long been accepted, and before writing documentation, it would probably be worthwhile to read Sergei Kovalev's tutorial (it's built into MQL4):
Everything is already taken care of, and before writing the documentation, it would probably be worthwhile to read Sergei Kovalev's tutorial (it is built into MQL4):
This is how a block can be constructed in which market and pending orders are analyzed:
{ //отражённым в терминале
if(OrderSelect(i-1,SELECT_BY_POS)==true)//Если есть следующий
{
// Здесь должен выполняться ..
// ..анализ характеристик ордеров
}
} //Конец тела цикла
The loop statement header contains the initial value i=1, and the condition for the loop termination is the expression i<=OrdersTotal(). Function OrdersTotal() returns the total amount of market and pending orders, i.e. those orders that are reflected in the Terminal on the Trade tab. Therefore, the number of iterations in the loop will be the number of orders present in the trade.
There's no need to cheat)
This is the code of MT4, and there is no division of orders and positions - everything is mixed together in it
Everything is already taken care of, and before writing the documentation, it would probably be worthwhile to read Sergei Kovalev's tutorial (it is built into MQL4):
This is how a block can be constructed in which market and pending orders are analyzed:
{ //отражённым в терминале
if(OrderSelect(i-1,SELECT_BY_POS)==true)//Если есть следующий
{
// Здесь должен выполняться ..
// ..анализ характеристик ордеров
}
} //Конец тела цикла
The loop statement header contains the initial value i=1, and the condition for the loop termination is the expression i<=OrdersTotal(). Function OrdersTotal() returns the total amount of market and pending orders, i.e. those orders that are reflected in the Terminal on the Trade tab. Therefore, the number of iterations in the loop will be the number of orders present in the trade.
Are the OrdersTotal() functions different in MQL4 and MQL5? It seems that the compiler is the same ....
Are the OrdersTotal() function in MQL4 and MQL5 different functions? The compiler seems to be the same ....
As for the trading functions, there are differences. I've already mentioned MQL4:
Forum on trading, automated trading systems and trading strategies testing
Peculiarities of mql5 language, tips and tricks
Vitaly Muzichenko, 2017.02.28 19:25
... I don't have any problems with mt4, and it has no division of orders and positions - it's all mixed together
Yes, different.
What's the difference?
Forum on trading, automated trading systems and trading strategies testing
Peculiarities of mql5, tips and tricks
Vladimir Karputov, 2017.02.28 19:44
As for the trading functions - there are differences. I've already mentioned above about MQL4:
What's the difference?
OrdersTotal().
Returns the number of active orders.
intOrdersTotal();
Returned value
Value of the int type.
Note
One should not confuse between active pending orders and positions, which are also displayed in the "Trade" tab of the "Toolbox" panel. An order is an order to conduct a trade operation, and a position is the result of one or more trades.
With "netting" of positions (ACCOUNT_MARGIN_MODE_RETAIL_NETTING and ACCOUNT_MARGIN_MODE_EXCHANGE) only one position can be opened for each symbol at any given time and it is the result of one or more deals. Positions and active pending orders, which are also displayed in the "Trade" tab of the "Toolbox" panel, should not be confused with each other.
When the positions are presented independently (ACCOUNT_MARGIN_MODE_RETAIL_HEDGING), several positions can be opened for each symbol simultaneously.
PositionsTotal()
It returns the number of open positions.
intPositionsTotal();
Returned value
Value of the int type.
Note
With "netting" positions (ACCOUNT_MARGIN_MODE_RETAIL_NETTING and ACCOUNT_MARGIN_MODE_EXCHANGE) only one position can be opened for each symbol at any moment and that is the result of one or more trades. Positions and active pending orders, which are also displayed in the "Trade" tab of the "Toolbox" panel, should not be confused with each other.
In the independent representation of positions (ACCOUNT_MARGIN_MODE_RETAIL_HEDGING), several positions can be opened for each symbol simultaneously.