Differntiate between Market and Pending Orders

 

Hey, 

I´m just programming my ea and have some questions,

I want to differentiate between pending and open orders,

Since I´m working with pending stopporders and my ea is placing them he should keep looking look for signals as long as there are only pending orders open,

but if there´s already one market order open he should wait until it is closed.(its fine if the pending orders are executed later on while another trade is open).

 

How can I code this ?

 Thanks in advance

 
skyblazer: I want to differentiate between pending and open orders,
Open orders have the type OP_BUY or OP_SELL.
 
whroeder1:
Open orders have the type OP_BUY or OP_SELL.

yea, but is there a function ? I only found the Orderstotal function with which I checked if( Orderstotal() == 0){ ... then open trade}

but this only works for both- pending and open orders. 

Well my main problem is that he no matter what opens too many trades. And I dont understand why, in one ea the above orderstotal works totally fine, and in the other he´s constantly opening a mass of orders when the signal is there. 
 

You have to write your own function for that.

You should find plenty of examples if you search for "count orders", but here is a basic example:

int countOpenOrders()
  {
   int cnt=0;
   for(int i=OrdersTotal()-1; i>=0; i--) // good habit to count down
     {
      if(!OrderSelect(i,SELECT_BY_POS)) continue;  // select the order
      if(OrderSymbol() != _Symbol)      continue;  // optional check for same symbol
      if(OrderMagicNumber()!= MagicNo)  continue;  // optional check for magic number
      if(OrderType() < 2)               cnt++;     // 0 == OP_BUY and 1 == OP_SELL
     }
   return(cnt);
  }

You can then call it like so:

if(countOpenOrders()<1) ...

(all uncompiled / untested)
 

 

Thanks, this can help me! 

 
skyblazer: I only found the Orderstotal function with which I checked if( Orderstotal() == 0){ ... then open trade}
Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.) Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forum
 
whroeder1:
Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.) Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forum
that makes sense.. thank you
Reason: