Download MetaTrader 5
To add comments, please log in or register
Install apps from the library right in MetaTrader. It is easy!
mohsen
13
mohsen 2015.03.08 11:55 
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
Carl Schreiber
6392
Carl Schreiber 2015.03.08 12:25  

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.

Keith Watford
Moderator
9537
Keith Watford 2015.03.08 12:35  
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--)
Carl Schreiber
6392
Carl Schreiber 2015.03.08 13:02  
Yes, thanks GumRai!
whroeder1
14239
whroeder1 2015.03.08 13:36  
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
mohsen
13
mohsen 2015.03.08 13:52  
thanks gooly , GumRai and WHRoeder  ......   problem is solve
/
To add comments, please log in or register