Download MetaTrader 5

Open Only 1 Position

To add comments, please log in or register
Kerim Horoz
58
Kerim Horoz 2016.04.03 21:35 

Hello, 

I would like to open an order at 21:00 for instance, but it opens more than 1 position at that time because of more than one tick at that time. Would you help me out what I need to add on my codes ?

 

Thanks 

Osama Shaban
1464
Osama Shaban 2016.04.04 10:20  

Add this function to check if there is an open order or not ...

bool ExistPositions(){
   for (int i=0; i<OrdersTotal(); i++) {
      if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNo) {
            return(True);
         }
      } 
   } 
   return(false);
}
Add ExistPositions() into your code logic where a new order will open ...  Like,
if(!ExistPositions() && a>b && ... && ...)
   OpenBuy();

To add comments, please log in or register