The number of pending orders (only system functions, no OOP).
CalculateAllPendingOrdersSystem function
//+------------------------------------------------------------------+ //| Calculate all pending orders for symbol | //+------------------------------------------------------------------+ int CalculateAllPendingOrdersSystem(const string symbol,const ulong magic) { int total=0; for(int i=OrdersTotal()-1; i>=0; i--) // returns the number of current orders { ulong order_ticket=OrderGetTicket(i); // selects the pending order by index for further access to its properties if(order_ticket==0) continue; string order_symbol=OrderGetString(ORDER_SYMBOL); // get symbol long order_magic=OrderGetInteger(ORDER_MAGIC); // get magic //--- if(order_symbol==symbol && order_magic==magic) total++; } //--- return(total); }
There are two pending orders with Magic '200' and one with Magic '100' in the market - only three pending orders (all three pending orders for the 'EURAUD' symbol).
Run the script:
//+------------------------------------------------------------------+ //| Script 1.mq5 | //| Copyright © 2021, Vladimir Karputov | //+------------------------------------------------------------------+ #property copyright "Copyright © 2021, Vladimir Karputov" #property version "1.000" #property script_show_inputs //--- input parameters input string InpSymbol = "EURUSD"; // Symbol input ulong InpMagic = 200; // Magic number //--- //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { int total=CalculateAllPendingOrdersSystem(InpSymbol,InpMagic); PrintFormat("Symbol %s, Magic %d, Pending Orders %d:",InpSymbol,InpMagic,total); } //+------------------------------------------------------------------+ //| Calculate all pending orders for symbol | //+------------------------------------------------------------------+ int CalculateAllPendingOrdersSystem(const string symbol,const ulong magic) { int total=0; for(int i=OrdersTotal()-1; i>=0; i--) // returns the number of current orders { ulong order_ticket=OrderGetTicket(i); // selects the pending order by index for further access to its properties if(order_ticket==0) continue; string order_symbol=OrderGetString(ORDER_SYMBOL); // get symbol long order_magic=OrderGetInteger(ORDER_MAGIC); // get magic //--- if(order_symbol==symbol && order_magic==magic) total++; } //--- return(total); } //+------------------------------------------------------------------+
We get the result:
2021.08.24 08:34:20.871 Script 1 (EURAUD,H1) Symbol EURUSD, Magic 200, Pending Orders 0: 2021.08.24 08:34:29.510 Script 1 (EURAUD,H1) Symbol EURAUD, Magic 200, Pending Orders 2: 2021.08.24 08:34:38.224 Script 1 (EURAUD,H1) Symbol EURAUD, Magic 100, Pending Orders 1:
Files:
Script_1.mq5
4 kb

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello,
I have made this function to count the pending orders in the account
it always return 0
i hope someone can help to know why it not work !
thanks,