Forex
Google

Go Back   Forex Trading > Metatrader Training > Metatrader 4 mql 4 - Development course > Questions
Forex Forum Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-13-2005, 10:58 PM
christan christan is offline
Junior Member
 
Join Date: Nov 2005
Posts: 5
christan is on a distinguished road
Function to effectively close all orders.

I have been using this function to try and close all my orders, both pending and open. However for some unknown reason, there's always unclosed orders remaining. How do I ensure that every single pending/open order closes?

Code:
// close all open and pending orders
void closeAllOrders()  {
   int total = OrdersTotal();
   for (int i=total-1; i>=0; i--)  {
      if (OrderSelect(i, SELECT_BY_POS))  {
         if (OrderType() == OP_BUY)  {
            OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 3, Red);
         } else if (OrderType() == OP_SELL)  {
            OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 3, Red);   
         } else if (OrderType() > 1)  {
            OrderDelete(OrderTicket());   
         }
      }
   }
} // end closeAllOrders()
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-02-2006, 05:26 PM
fxid10t's Avatar
fxid10t fxid10t is offline
Member
 
Join Date: Sep 2005
Location: MidAtlantic USA
Posts: 72
fxid10t is on a distinguished road
Red face try this maybe?

Code:
// close all open and pending orders
void closeAllOrders()  {
   for(int c=0;c<OrdersTotal();c++) {
      OrderSelect(c,SELECT_BY_POS,MODE_TRADES); 
         if (OrderType() == OP_BUY)  {
            OrderClose(OrderTicket(), OrderLots(),Bid,3, Red);  }
         if (OrderType() == OP_SELL)  {
            OrderClose(OrderTicket(), OrderLots(), Ask,3, Red);  }   
         if (OrderType() > 1)  { OrderDelete(OrderTicket()); }
   }
} // end closeAllOrders()
__________________
"You should not have a favourite weapon. To become over-familiar with one weapon is as much a fault as not knowing it sufficiently well. You should not copy others, but use weapons which you can handle properly. It is bad for commanders and troopers to have likes and dislikes. These are things you must learn thoroughly." Miyamoto Musashi
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sleep function in EA between orders icek Metatrader 4 2 06-11-2007 04:10 PM
modify orders and close pending orders bkgridley Questions 8 05-23-2007 09:49 PM
SHI Silvertrend close orders EA?? fxbrandon Expert Advisors - Metatrader 4 1 11-29-2006 08:17 PM
Script close all orders paulosilva555 Metatrader 4 1 02-17-2006 04:19 PM
close all orders mas Metatrader 4 2 02-15-2006 08:14 AM


All times are GMT. The time now is 10:49 AM.