Deleting pending order fails

 
for(i=0;i<=OrdersTotal();i++)
            
{
            
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
                  
if (OrderType() != 0 || OrderType() != 1)
                  
OrderDelete(OrderTicket());
                  
}
Hello! I was just wondering that how is it possible with this code to have 3 buy orders left open if in that particular case:

- price of 1.32987 buy order opens immediately when the EA starts
- at the time when the above buy order opened price of 1.33037 and 1.32919 pending buy orders placed as well
(there are pending sell orders as well but that doesn't matter now, i think)

So if the price movement triggers one if the pending buy order, the other should be deleted by the EA
But today morning 3 buy market order were in the terminal
How can it happen if there is about 100 points range between the 2 buy pending orders, the currency is EURUSD with roughly 20 points spread
and the EA runs at night and between the 2 buy pending orders opening there was a 4 hours long period (see the picture below)

I just can't figure it out


 
bolyhos:


I just can't figure it out

I don't think your OrderDelete() fails, but if it does don't you want to know why ? and if it does wouldn't you want to know some additional information ? such as Bid, Ask, OrderOpenPrice(), etc ?

Read this: What are Function return values ? How do I use them ?


This is why all your pending order are not deleted, your loop needs to count down, not up . . .: Loops and Closing or Deleting Orders

 
Thank you very very much!!!

Those articles were really helpful. Is there any collection of that type of articles where the functions and problems go with them are analyzed in details. Because mql4 documentation does not explain everything like this.
 
bolyhos:
Thank you very very much!!!

Those articles were really helpful. Is there any collection of that type of articles where the functions and problems go with them are analyzed in details. Because mql4 documentation does not explain everything like this.
Only if someone writes one for free in their own time . . . I wrote them in response to people asking the same question time and time again, it is easy just to post a link to the threads. A thread where links to this type of thread could be posted would be useful, the hindrance to trying to do this is that Moderators cannot make posts sticky, so it would need a request to Admin to make it sticky and re-stick it each time it became unstuck . . .
Reason: