Open Only 1 Position

 

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 

 

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();

Reason: