- Question: How to close multi-open-trades at once
- Hotkeys for Buy and Sell
- Close open position one shot manually
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()); } } } }
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.
Thanks! I gave that a try and it is still closing 1 by 1.
Unfortunately, that code is wrong. Use this
void CloseAllTrades() { for (int i=OrdersTotal()-1;i>=0; i--) { if (OrderSelect(i, SELECT_BY_POS)) { if (OrderSymbol()==Symbol()) { if (OrderType()<=OP_SELL) OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),5,Violet); else OrderDelete(OrderTicket()); } } } }
You MUST refreshRates between each server call.
Not necessary.
Unfortunately, that code is wrong. Use this
Thanks, but it is the same. closing 1 by 1.
Thanks, but it is the same. closing 1 by 1.
If you want to close all orders at all, try this
void CloseAllTrades() { for (int i=OrdersTotal()-1;i>=0; i--) { if (OrderSelect(i, SELECT_BY_POS)) { if (OrderType()<=OP_SELL) OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),5,Violet); else OrderDelete(OrderTicket()); } } }
alternative close trade by...
may be usefull for you...
void closebuy()
{
int total=OrdersTotal(),i;
for(i=total-1; i>=0; i--)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if ((OrderType()==OP_BUY) || OrderSymbol()==Symbol())
{
OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,CLR_NONE);
}
}
return(0);
}
void closesell()
{
int total=OrdersTotal(),i;
for(i=total-1; i>=0; i--)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if ((OrderType()==OP_SELL) || OrderSymbol()==Symbol())
{
OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,CLR_NONE);
}
}
return(0);
}
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use