How to check open in the market orders only

 

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:

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);
}
 

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.


 
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).
 
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.

 
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);   
}
 
josemiguel1812:

A solution can be...

The question is about mql4.
Reason: