Download MetaTrader 5
To add comments, please log in or register
They are already making profit from their signals. Publish your signal and join them!
Yassine
6
Yassine 2016.11.28 19:48 

I have a pending order, and I want to check if it's opened or not, for the reason to delete an other one.

I tryed to use the fact that OrderType() change value when Order is open from OP_BUYLIMIT ( for example ) to OP_BUY but this is not working, it chang value only if the oreder is closed by stoploss or takeprofit.

if any one coulde helpe me i woud be thankful. 

 

PS : this is for mql4. Thanks ! 

whroeder1
13605
whroeder1 2016.11.28 19:50  
Yassine: I tryed to use the fact that OrderType() change value when Order is open from OP_BUYLIMIT ( for example ) to OP_BUY but this is not working,
We can't see your broken code
eevviill14
71
eevviill14 2016.11.28 20:27  

Count all types of orders.

int buys_,sells_,buys_S,sells_S,buys_L,sells_L,Orders_Total;
...
////////////////////////////////////////////////////////////////////////////////////
void CountOpenedPositions_f()
{
buys_=0;
sells_=0;
  buys_S=0;
sells_S=0;
  buys_L=0;
sells_L=0;
Orders_Total=0;


for (int i=OrdersTotal()-1; i>=0; i--)
{
   if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
   if(OrderMagicNumber()!=Magic || OrderSymbol()!=Symbol()) continue;
      
     int type=OrderType();
    
   if(type==OP_BUY)      buys_++;
    else
   if(type==OP_SELL)     sells_++;
    else
   if(type==OP_BUYSTOP)      buys_S++;
    else
   if(type==OP_SELLSTOP)     sells_S++;
    else
   if(type==OP_BUYLIMIT)      buys_L++;
    else
   if(type==OP_SELLLIMIT)     sells_L++;
}

Orders_Total=buys_+sells_+buys_S+sells_S+buys_L+sells_L;
}


 Than(for example)

if(buys_>buys_S) delete sellStop 

/
To add comments, please log in or register