Help needed

 

 
Use Time[] and TimeCurrent() to check.
 

there. I didn't test it.


bool can_trade_new_bar()
{   
   //iterate through last ten trades. You can adjust this value above or below
   for(int i=OrdersHistoryTotal()-1; i>=OrdersHistoryTotal()-10;i--)
   {
       if(!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
          continue;
       if( iBarShift(Symbol(),Period(),OrderCloseTime(),false)==0) //current bar should be zero shift. You can verify it.
          return(false);
   }
  return(true);
}
 
int BarTraded = 0;

bool NewBar()
{
   static datetime lastbar;
   datetime curbar = Time[0];
   if(lastbar != curbar){
      BarTraded = 0;
      lastbar=curbar;
      return (true);
   }
   return(false);
}
Whenever you open an order, don't forget to do "BarTraded = 1;" if opening the order was successful. And always check to make sure that "BarTraded == 0" before opening an order.

.

Jon

Reason: