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

 14 wangjh2004 2007.05.28 08:02   请问 : 当持有双向仓时, 如何计算某种货币所持有的多单和空单各自的总量?
 版主28441 Rosh 2007.05.29 17:49 #   This is a script.
 版主28441 Rosh 2007.05.29 17: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); } //+------------------------------------------------------------------+```
 14 wangjh2004 2007.05.30 04:13 #   Thank you! Rosh.
 版主28441 Rosh 2007.05.30 10:56 #   You're welcome.