for(int i=0; i <= OrdersTotal(); i++){ if(OrderSelect(i,SELECT_BY_POS) == true)
If there are five orders, their position is zero to four, it will fail on position five.- You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So Don't write if(bool == true), just use if(bool) or if(!bool).
- In the presence of multiple orders (one EA multiple charts, multiple EA's,
manual trading)
you must count down when closing/deleting/modifying in a position loop.
Get in the habit of always counting down. Loops and Closing or Deleting Orders - MQL4 forum
if(OrderSymbol() != Symbol()) continue;
No Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including manual trading.) Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forumif(OrderType() > 1)
Don't hard code numbers. Use the Order Properties - Trade Constants - Standard Constants, Enumerations and Structures - MQL4 Reference- LifeHack: However, is it possible that if the OrderSelect fails to select the order at say i=0 it will then continue the "for" loop for the next iteration, i=1, having not counted the order at i=0? Therefore it is possible that the wrong number of trades will be counted. I guess you could insert an additional while (true) loop with Fun_Error function, but just wondering if that is unnecessary?It will fail at position zero only if you have no open orders. You are over thinking it.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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 have a question regarding the below code. It is meant to search the open orders and count how many open buy and sells their are for the correct symbol. In this case there should only be 1 buy order open. However, is it possible that if the OrderSelect fails to select the order at say i=0 it will then continue the "for" loop for the next iteration, i=1, having not counted the order at i=0? Therefore it is possible that the wrong number of trades will be counted. I guess you could insert an additional while (true) loop with Fun_Error function, but just wondering if that is unnecessary?