Problem with several order placement

 

I have a simple EA. It works as follow: 

If there is no open order, It should place one BUY. But it place several Buy at the same time.

I dont know why!!

void OnTick()
{
   int a;
   int b;
   if (NoOpenOrder()) 
      {
         if(FirstOrder==Buy)     a= OrderSend("EURUSD.e",0,0.1,MarketInfo("EURUSD.e",MODE_ASK),0,0,0,NULL,0,0,clrNONE); 
         else                    b= OrderSend("EURUSD.e",1,0.1,MarketInfo("EURUSD.e",MODE_BID),0,0,0,NULL ,clrNONE);
      }
}
//////////////////////////////////////////////
bool NoOpenOrder()  
   {
      int num=0;
      for(int k=0;k<OrdersTotal();k++)
         {   
           if(OrderSelect(k,SELECT_BY_POS,MODE_TRADES))
            num++;
         }
      if(num==0)
         { 
            return(true);
         }
      else 
         return(false);   
    }
 

Forum on trading, automated trading systems and testing trading strategies

When you post code please use the CODE button (Alt-S)!

Use the CODE button

Thank you.

Reason: