Download MetaTrader 5

Closing all trades

To add comments, please log in or register
One billion tasks have already been executed with MQL5 Cloud Network. Test trading robots even faster!
raven.chrono
324
raven.chrono 2014.07.07 11:51 

Hi.


I have this small problem. I have created an EA that closes all open trades when it hits a certain profit or loss and it is working fine but when i opened 200 trades then activate it when it hits 2000 profit, it only closes by batch but not all using this code.


for(int x=0;x<OrdersTotal();x++)
{
  if(OrderSelect(x,SELECT_BY_POSITION)==true)
  {
     OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,clrNONE);
  }
}

do you have any best solution for this one?
Keith Watford
Moderator
9603
Keith Watford 2014.07.07 12:24  
raven.chrono:

Hi.


I have this small problem. I have created an EA that closes all open trades when it hits a certain profit or loss and it is working fine but when i opened 200 trades then activate it when it hits 2000 profit, it only closes by batch but not all using this code.



It's been mentioned so many times on this forum already

COUNT DOWN WHEN CLOSING ORDERS 

for(int x=OrdersTotal()-1;x>=0;x--)

 I expect WHRoedor will be along with a link that will explain why soon.

honest_knave
Moderator
2159
honest_knave 2014.07.07 12:39  
To add comments, please log in or register