该函数简洁明了,分别获取当前持仓单中多单和空单的总手数。可以调用到指标或EA中。
- double LotsCount(int type)
- {
- double BuyLots=0;
- double SellLots=0;
- for (int t=0; t<OrdersTotal(); t++)
- {
- cg=OrderSelect(t, SELECT_BY_POS, MODE_TRADES);
- if (OrderType() == OP_BUY && OrderMagicNumber() == MagicNumber )BuyLots+=OrderLots();
- if (OrderType() == OP_SELL && OrderMagicNumber() == MagicNumber )SellLots+=OrderLots();
- }
- switch(type)
- {
- case OP_BUY: return (BuyLots);
- break;
- case OP_SELL: return (SellLots);
- break;
- }
- return(0);
- }
|