Need help Closing orders with an EA
  #1 (permalink)  
Old 03-28-2008, 06:11 PM
Freshman
 
Join Date: Jun 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
dtomassino is on a distinguished road
Default Need help Closing orders with an EA

I ran into a problem that I dont know how to solve. My program has a few open orders and closes them all together but sometimes I think that some of the orders are not filled therefore it keeps waiting till they are filled and that locks up my program. What have you guys found to be the best way to close all open orders? Thank you kindly for your help.

here is the code:



int OrdersTotalLong()
{
int order_total = 0;

for (int i = 0; i < OrdersTotal(); i++)
{
OrderSelect(i,SELECT_BY_POS, MODE_TRADES);
if (OrderType() == OP_BUY)
order_total++;
}
return(order_total);
}
int MaxLongOrder()
{
int order = 0;
double lotsbuyed = 0;

for (int i = 0; i < OrdersTotal(); i++)
{
OrderSelect(i,SELECT_BY_POS, MODE_TRADES);
if ((OrderType() == OP_BUY) && (OrderLots() > lotsbuyed))
{
lotsbuyed = OrderLots();
order = i;
}
}
return(order);
}


int CloseLong()
{
while (OrdersTotalLong() > 0) //until there's no Orders open (close all)
{
if (OrderSelect(MaxLongOrder(), SELECT_BY_POS, MODE_TRADES) == false) continue;

OrderClose(OrderTicket(),OrderLots(), Bid, 3, Green);
}


}
return(0);
}
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
place 2 pending orders pgtips MetaTrader and ZeroCode 1 11-15-2007 03:15 PM
Merging orders TraderSeven MetaTrader and ZeroCode 7 12-10-2005 01:19 AM
Closing trades at end of candle TraderSeven MetaTrader and ZeroCode 2 09-22-2005 02:53 PM
Closing with RSI TurboTrader24 MetaTrader and ZeroCode 1 09-07-2005 03:50 AM
Closing Pending Orders Rastarr MetaTrader and ZeroCode 0 06-07-2005 11:52 PM


All times are GMT. The time now is 11:08 PM.
Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.1.0

Registered members have access to special online forex currency trading tools, software, mt4 expert advisors and indicators. Register now