该函数获取指定货币对订单数量及执行全部平仓。是两个函数模块,一个获取指定的货币对订单数量,一个是全部平仓,可以自行添加其它过滤条件调用到EA中。
- #define MagicNumber 123456
- extern string sym ="EURUSD";
- int openorders = 0;
- int CalculateCurrentOrders(string symbol)
- {
- int buys=0,sells=0;
- //----
- for(int i=0;i<OrdersTotal();i++)
- {
- if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
- if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
- {
- if(OrderType()==OP_BUY) buys++;
- if(OrderType()==OP_SELL) sells++;
- }
- }
- return(buys+sells);
- }
- openorders=CalculateCurrentOrders(sym);
- bool CloseALL()
- {
- int ot = OrdersTotal();
- for(int i=0;i<ot;i++)
- {
- if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==false) return(false);
- if(OrderMagicNumber()!=MagicNumber|| OrderSymbol()!=sym) continue;
- if(OrderType()==OP_BUY)
- {
- if (!OrderClose(OrderTicket(),OrderLots(),Bid,3,White))
- {
- Print("OrderClose with error #" + GetLastError() + OrderTicket());
- return(false);
- }
- }
- if(OrderType()==OP_SELL)
- {
- if (!OrderClose(OrderTicket(),OrderLots(),Ask,3,White))
- {
- Print("OrderClose with error #" + GetLastError() + OrderTicket());
- return(false);
- }
- }
- }
- openorders=0;
- return(true);
- }
|