Download MetaTrader 5

How to check open in the market orders only

To add comments, please log in or register
Do you have questions to the application's developer - ask them in Comments section
Donskey
150
Donskey 2014.05.04 11:04 

Hi

I would like to call a function that will only run if there is no open market orders.

It is OK if there are pending orders open but I do not want to call my function if there are any open in the market orders.

How can I check if there are open/none in the market orders?

OrdersTotal() returns market and pending orders, but I only want to know if there are any market orders open. Thx in advance

Donskey
150
Donskey 2014.05.04 11:25  
Donskey:

Hi

I would like to call a function that will only run if there is no open market orders.

It is OK if there are pending orders open but I do not want to call my function if there are any open in the market orders.

How can I check if there are open/none in the market orders?

OrdersTotal() returns market and pending orders, but I only want to know if there are any market orders open. Thx in advance

Sorry for the bother I think I worked it out

bool GetAnyOpenMarketOrders()
{
   bool openMarketOrderFound = false;
  
   for(int i = OrdersTotal() -1; i >= 0; i--)
   {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true)
         if((OrderType() == OP_BUY) || (OrderType() == OP_SELL))
            openMarketOrderFound = true;
    }
   return(openMarketOrderFound);
}
Alain Verleyen
Moderator
30739
Alain Verleyen 2014.05.04 13:55  

Forum on trading, automated trading systems and testing trading strategies


Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.


Alain Verleyen
Moderator
30739
Alain Verleyen 2014.05.04 13:57  
Donskey:

Sorry for the bother I think I worked it out

Congratulations. However I suggest you to check the used symbol (if you run your ea on several symbols) and also eventually the magic number (if you run more than one EA on a symbol).
Donskey
150
Donskey 2014.05.04 15:25  
angevoyageur:
Congratulations. However I suggest you to check the used symbol (if you run your ea on several symbols) and also eventually the magic number (if you run more than one EA on a symbol).

Oops, yes sorry & thx will do next time.

Yes of course, only left it very simple to get it working then add all the appropriate checks.

Jose Miguel Soriano
4963
Jose Miguel Soriano 2014.05.05 20:30  
Donskey:

Hi

I would like to call a function that will only run if there is no open market orders.

It is OK if there are pending orders open but I do not want to call my function if there are any open in the market orders.

How can I check if there are open/none in the market orders?

OrdersTotal() returns market and pending orders, but I only want to know if there are any market orders open. Thx in advance

A solution can be...

//---------------------------------- EXISTEN POSICIONES ABIERTAS ------------------------------
bool existePosicAbierta(string simb= NULL)
{
   bool resp= false;
   resp= simb==NULL? PositionsTotal()>0: PositionSelect(simb);
   return(resp);   
}
Alain Verleyen
Moderator
30739
Alain Verleyen 2014.05.06 01:53  
josemiguel1812:

A solution can be...

The question is about mql4.
To add comments, please log in or register