difficulty with pending orders

 

Hi i have created an expert adviser that places pending orders after each new bar and closes any previous pending orders. However I would like my adviser to stop placing pending orders once a pending order price is met and i am unsure how to go about doing this. I was hoping somebody may have some helpful advice about how to do this?

 

Thanks 

 
robertebuck:

Hi i have created an expert adviser that places pending orders after each new bar and closes any previous pending orders. However I would like my adviser to stop placing pending orders once a pending order price is met and i am unsure how to go about doing this. I was hoping somebody may have some helpful advice about how to do this?

 

Thanks 

int         openBuy;
int         openSell;

void countOpenOrders()
{
   openBuy  = 0;
   openSell = 0;
   for(int i=OrdersTotal()-1; i >= 0; i--)
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType() == OP_BUY) openBuy ++;
            if(OrderType() == OP_SELL) openSell++;
           }
}
You can count your open order like this and insert a condition to place pending orders only if openBuy == 0 && openSell == 0.
 
I believe the code you have given me only works for MTQL4 i am however using MTQl5. I should have made that clear in my original post.
 
robertebuck:
I believe the code you have given me only works for MTQL4 i am however using MTQl5. I should have made that clear in my original post.
Even if the syntax may differ a little you can use the logic. Hit F1 if you do not know how or pay five bucks for someone who puts you the snippet together.