problem close all open positions at a point in EA

 
Hi
I'm learn programming
I write a program but it have problem.
it can not close all open positions at a point
Please see

Please solve my problem 
thanks
Files:
test.mq4  3 kb
 

1) you don't check OrderSelect(), what if it fails?

2) if you want to close orders you need to count down!

/*wrong*/ for(int i=1; i<OrdersTotal(); i++)  ..
/*to do*/ for(int i=OrdersTotal()-1; i<=0; i--) ..

This might solve your problem.

 
gooly:

1) you don't check OrderSelect(), what if it fails?

2) if you want to close orders you need to count down!

This might solve your problem.


Typo

/*to do*/ for(int i=OrdersTotal()-1; i<=0; i--)
 
Yes, thanks GumRai!
 
gooly:

1) you don't check OrderSelect(), what if it fails?

2) if you want to close orders you need to count down!

  1. Check your return codes (OrderSelect and OrderClose) What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  2. You must count down when closing/deleting in a position loop. Get in the habit of always counting down. Loops and Closing or Deleting Orders - MQL4 forum
 
thanks gooly , GumRai and WHRoeder  ......   problem is solve
Reason: