Questions from Beginners MQL4 MT4 MetaTrader 4 - page 219
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
I always knew that it contains the number of orders -1, i.e. OrdersTotal()-1 and everything was working, but I started writing a program and suddenly, one order is no longer counted, I asked for OrdersTotal() and it gave me the total number of orders = 3, instead of 3-1.
What happens?
The usual form of the loop in the help:
int total=OrdersTotal();
for(int pos=0;pos<total;pos++)
{
}
That is, the first order is equal to zero.
But no, in fact, the first order is 1, which means that we should start the search from 1 and not from zero?
Have the metaquotes done something wrong or am I stupid?
Hello, what's up with OrdersTotal()?
I always knew that it contains the number of orders -1, so OrdersTotal()-1 and everything was working, but I started writing a program and suddenly one order is not taken into account and I asked for OrdersTotal() and it says total orders = 3, instead of 3-1.
What happens?
The usual form of the loop in the help:
int total=OrdersTotal();
for(int pos=0;pos<total;pos++)
{
}
That is, the first order is equal to zero.
But no, in fact, the first order is 1, which means that we should start the search from 1 and not from zero?
Have the metaquotes done something wrong, or am I stupid?
You've mixed up the RELATED ORDERS and POISONS. Read the reference. Be more specific in your question: what are you trying to count: REMOVED ORDERS or POSITIONS? And yes, nothing has changed - the first element index starts with '0'.
Added: example
Example: Calculate Positions and Pending Orders
You've mixed up the RELATED ORDERS and the POSITIONS. Read the reference. Form your question more precisely: what are you trying to count: RETIRED ORDERS or POSITIONS? And yes, nothing has changed - the first element index starts with '0'.
Added: example
Example: Calculate Positions and Pending Orders
I mean MQL4, not MQL5, there is no difference between pending and market orders!
I mean MQL4, not MQL5, there's no division into pending and market pending!
You are writing in MQl5 forum. You are writing in the main section. You post in the MQL5 forum - and you will get answers about MQL5.
Questions on the old terminal are addressed to the special section: MQL4 and MetaTrader 4. From now on, write there. I will transfer your questions to it.
I compared two variants, in the first one, I used OrdersTotal()-1 and started the search from zero - got the error
. In the second variant, I started with one and took the whole OrdersTotal() - no error this time
In the screenshots, you can see that OrdersTotal() shows the actual number of orders, not OrdersTotal()-1 ...
The question is why OrdersTotal() shows the actual number of orders, rather than -1, should it be like this or it is something new?
Because in this case, we should start the search not from zero, but from one!
I compared two variants, in the first one, I used OrdersTotal()-1 and started the search from zero - got the error
. In the second variant, I started with one and took the whole OrdersTotal() - no error this time
In the screenshots, you can see that OrdersTotal() shows the actual number of orders, not OrdersTotal()-1 ...
The question is why OrdersTotal() shows the actual number of orders, rather than -1, should it be like this or it is something new?
Because in this case, we should start the search not from zero, but from one!
I think I understood my error, sorry...
There is an offset of -1 in this condition:
if (OrderSelect(i-1,SELECT_BY_POS)==true){}
Sorry for being blunt, I took the string from another program and didn't pay attention to the offset!