下载MetaTrader 5
要添加评论,请登录注册
在代码库发布程序。提高您的等级!
wangjh2004
40
wangjh2004 2007.05.28 06:02 
请问 : 当持有双向仓时, 如何计算某种货币所持有的多单和空单各自的总量?
Rashid Umarov
管理员
6601
Rashid Umarov 2007.05.29 15:49  
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. |
//|                                        http://www.metaquotes.net/ru/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link      "http://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;
//----
   buyNumber=0;
   sellNumber=0; 
   buyLimitNumber=0;
   sellLimitNumber=0;
   buyStopNumber=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_BUY: buyNumber++;break;
               case OP_SELL: sellNumber++;break;
               case OP_BUYLIMIT: buyLimitNumber++;break;
               case OP_SELLLIMIT: sellLimitNumber++;break;
               case OP_BUYSTOP: buyStopNumber++;break;
               case OP_SELLSTOP: sellStopNumber++;break;
               }
            }
         }
//----
   res=buyNumber+sellNumber+buyLimitNumber+sellLimitNumber+buyStopNumber+sellStopNumber;
   return(res);   
   }
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   int buys,sells,buyLs,sellLs,buySts,sellSts;
   if (MyOrdersTotal(buys,sells,buyLs,sellLs,buySts,sellSts,ExpertMagicNumber)>0)
   Print("Long=",buys," Short=",sells,"  Buy limit=",buyLs,"  Sell Limit=",sellLs," Buy Stop=",buySts," Sell Stop=",sellSts);
//----
   return(0);
  }
//+------------------------------------------------------------------+
Rashid Umarov
管理员
6601
Rashid Umarov 2007.05.29 15:49  
This is a script.
wangjh2004
40
wangjh2004 2007.05.30 02:13  
Thank you! Rosh.
Rashid Umarov
管理员
6601
Rashid Umarov 2007.05.30 08:56  
You're welcome.
/
要添加评论,请登录注册