Download MetaTrader 5

difficulty with pending orders

To add comments, please log in or register
Publish programs in Code Base. Improve your rating!
robertebuck
10
robertebuck 2016.08.20 22:33 

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 

Jan Tarnogrocki
6335
Jan Tarnogrocki 2016.08.21 19:59  
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.
robertebuck
10
robertebuck 2016.08.22 20:20  
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.
Jan Tarnogrocki
6335
Jan Tarnogrocki 2016.08.25 09:19  
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.
To add comments, please log in or register