How to get "# of open trades from other symbols, order type and magic number" ?

 

Hello All, I am a newbie. Could you please help me? I need to get "# of open trades from other symbols, order type and magic number". Let say: I want to open OP_BUY EURUSD if there is an OP_SELL GBPUSD.
Is there any way to tweak source code below?
int TradesCount(int type) //returns # of open trades for order type, current symbol and magic number { int result = 0; int total = OrdersTotal(); for(int i = 0; i < total; i++) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false) continue; if(OrderMagicNumber() != MagicNumber || OrderSymbol() != Symbol() || OrderType() != type) continue; result++; } return(result); } Thanks

 
  1. Formate code with the styler in the editor
  2. Post code as code by either Alt+S or
  3. Here is a list of all functions: https://www.mql5.com/en/docs/function_indices
  4. And here the list of the trading functions: https://www.mql5.com/en/docs/function_indices
  5. There you find either OrdersTotal or PositionsTotal to start a loop through either all open orders or positions. In the loop continue if the Symbol doesn't match.
Documentation on MQL5: List of MQL5 Functions
Documentation on MQL5: List of MQL5 Functions
  • www.mql5.com
List of MQL5 Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5