problem close all open positions at a point in EA

Back to topics list To post a new topic, please log in or register
avatar
3
mohsenvix 2015.03.08 12: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
Attached files:
  test.mq4  (2.18 KB)
avatar
2017
gooly 2015.03.08 13: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.


avatar
Moderator
3407
GumRai 2015.03.08 13: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--)

 

avatar
2017
gooly 2015.03.08 14:02 #
 
Yes, thanks GumRai!
avatar
12985
WHRoeder 2015.03.08 14: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

avatar
3
mohsenvix 2015.03.08 14:52 #
 
thanks gooly , GumRai and WHRoeder  ......   problem is solve
Back to topics list  

To add comments, please log in or register