forked from tolgagolbasi/Finance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloseall.mq4
49 lines (37 loc) · 1.37 KB
/
closeall.mq4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//+------------------------------------------------------------------+
//| close-all-orders.mq4 |
//| Copyright © 2005, Matias Romeo. |
//| Custom Metatrader Systems. |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Matias Romeo."
#property link "mailto:matiasDOTromeoATgmail.com"
int start()
{
int total = OrdersTotal();
for(int i=total-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
int type = OrderType();
bool result = false;
switch(type)
{
//Close opened long positions
case OP_BUY : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
break;
//Close opened short positions
case OP_SELL : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
break;
//Close pending orders
case OP_BUYLIMIT :
case OP_BUYSTOP :
case OP_SELLLIMIT :
case OP_SELLSTOP : result = OrderDelete( OrderTicket() );
}
if(result == false)
{
Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
Sleep(3000);
}
}
return(0);
}