MQL4 - automated forex trading   /  

Forum

How to close multi-open-trades at one shot

Back to topics list To post a new topic, please log in or register

avatar
2
chehab 2007.08.28 00:24 
we would like to hv somebody telling us on how to close several opened trades at one shot and not to close them individually or one by one.
article

Expert Advisors Based on Popular Trading Systems and Alchemy of Trading Robot Optimization

This article dwells on implementation algorithm of simplest trading systems. The article will be useful for beginning traders and EA writers.


avatar
276
wackena 2007.08.28 11:02 

Try this:

The attached script file should close all orders at same time. Place it in script folder and compile. Just drag to chart screen when needed. I haven't tested it. Hope it works.

Another way is to code it inside EA to CloseAllTrades when called.

if(x==?) CloseAllTrades(); // insert a call in int start() section of EA.
 
// insert this following code after 
// int start() {  
 
// } section of EA.
 
void CloseAllTrades() {
   for (int i=0; i<OrdersTotal(); i++) { 
      if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { 
         if (OrderSymbol()==Symbol()) { 
            if (OrderType()==OP_BUY) 
               OrderClose(OrderTicket(),OrderLots(),Bid,5,Violet);
            if (OrderType()==OP_SELL) 
               OrderClose(OrderTicket(),OrderLots(),Ask,5,Violet);
            if (OrderType()==OP_SELLSTOP || OrderType()==OP_SELLLIMIT || 
                OrderType()==OP_BUYSTOP || OrderType()==OP_BUYLIMIT) 
               OrderDelete(OrderTicket());
         }
      }
   }
}
Attached files:
  CloseAllTrades.mq4 (1.53 KB)
Back to topics list  

To add comments, please log in or register