Download MetaTrader 5

problem close all open positions at a point in EA

To add comments, please log in or register
mohsen
13
mohsen  
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
6691
Carl Schreiber  

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
9641
Keith Watford  
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
6691
Carl Schreiber  
Yes, thanks GumRai!
whroeder1
14780
whroeder1  
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  
thanks gooly , GumRai and WHRoeder  ......   problem is solve
To add comments, please log in or register