My EA opens multiple orders in a pair... Any Solution to this.

 

I designed an EA using parabolic Sar and price action. But the EA continue to open multiple order in the same pair. And i only want to open a trade in a single pair. Any solution will be appreciated please. Here is the code for execution

if(direction==1)
       {
         ssl=0;
         stp=0;
       if(StopLoss!=0)ssl = Bid+(StopLoss*pips);/////
       if(TakeProfit!=0)stp = Bid-(TakeProfit*pips);      
       /*if(OrdersTotal() == 0) */  if(OpenOrdersPair (Symbol())==0)
       if (OrderMagicNumber() != MagicNumber) 
        if ( OrderSymbol()!=Symbol() ) 
       ticket = OrderSend (Symbol(),OP_SELL,LotSize,Bid,3,ssl,stp,NULL,MagicNumber,0,Red);
       //if(ticket>0) OrderModify(ticket, OrderOpenPrice(),ssl,stp,0, clrNONE);
       }



 int OpenOrdersPair(string pair)
  {
   int total = 0;
      for(int i = OrdersTotal()-1; i>=0; i--)
         ticket = OrderSelect( i, SELECT_BY_POS, MODE_TRADES);
            if (OrderSymbol() == pairs) total++;
   return(total);
   }
   
      
       if(ticket <0)
                     {
                     Print ("Ordermodify error:", GetLastError());
                     }
                     else{ 
                     Print("Order modify successfully");




                     }    
   }
Reason: