# 如何计算某种货币所持有的多单和空单各自的总量?

40

12320

This sample about How to calculate numers of each type orders. See it, I hope this is will help you.

```//+------------------------------------------------------------------+
//|                                                     MyOrders.mq4 |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                        https://www.metaquotes.net/ru/ |
//+------------------------------------------------------------------+
#property show_inputs

extern int ExpertMagicNumber=123456;
//+------------------------------------------------------------------+
//|   Calculate all type orders by my MagicNumber                    |
//+------------------------------------------------------------------+
int MyOrdersTotal(int & buyNumber, int & sellNumber,int & buyLimitNumber
,int & sellLimitNumber,int & buyStopNumber, int & sellStopNumber, int MagicNumber=0 )
{
int res,orderType;
//----
sellNumber=0;
sellLimitNumber=0;
sellStopNumber=0;
for (int i=OrdersTotal()-1;i>=0;i--)
if (OrderSelect(i,SELECT_BY_POS))
{
if (MagicNumber==0 || (OrderMagicNumber()==MagicNumber && MagicNumber!=0))
{
switch(OrderType())
{
case OP_SELL: sellNumber++;break;
case OP_SELLLIMIT: sellLimitNumber++;break;
case OP_SELLSTOP: sellStopNumber++;break;
}
}
}
//----
return(res);
}
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+```

12320

This is a script.
40

Thank you! Rosh.

12320

You're welcome.