I need a code

 
Hi
I have problem at writing a code for close positions
I need a code that  if price was higher than the open buy position to close position(for buy mode)
And
If the price was less than open sell position to close position(for sell mode)
please help me

thanks

bool BuyMode;
bool SellMode;
double slB;
double slS;
extern double Price_Distance=10; 
extern double LotSize=0.2;
int ticket;
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {

// BUY AND SELL MODES------------------------------------------------+

   BuyMode  = ((iWPR(NULL,0,2,1)>-30));
   SellMode = ((iWPR(NULL,0,2,1)<-70));

// StopLoss & TakeProfit---------------------------------------------+

   slB = iLow (Symbol(), 0 , iLowest (Symbol(),0,MODE_LOW , 2000 , 0) );
   slS = iHigh(Symbol(), 0 , iHighest(Symbol(),0,MODE_HIGH, 2000 , 0) );


//Orders Counting & Close Orders------------------------------------+

   int orderscnt=0;
for(int i=OrdersTotal()-1;i>=0;i--)
     {
      //--------------------------------------
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if((OrderSymbol()==Symbol()) && ((OrderType()==OP_SELL) || (OrderType()==OP_BUY)))
        {
         orderscnt++;
        }

      //-Close Positione Buy if
      if((OrderSymbol()==Symbol()) && (OrderType()==OP_BUY)) 
        {
          OrderClose(OrderTicket(),OrderLots(),Bid,1,Black);
     
     }

      //-Close Positione Sell if 
      if((OrderSymbol()==Symbol()) && (OrderType()==OP_SELL))
        {
         OrderClose(OrderTicket(),OrderLots(),Ask,1,Black);
        }
     }



// Buy AND Sell Orders ----------------------------------------------+

   if((BuyMode) && (orderscnt<1))
     {
      ticket=OrderSend(Symbol(),OP_BUY,LotSize,Ask,2,slB,0,"Nothing",123456789,0,Blue);
     }

   if((SellMode) && (orderscnt<1))
     {
      ticket=OrderSend(Symbol(),OP_SELL,LotSize,Bid,2,slS,0,"Nothing",123456789,0,Red);
     }

   return(0);
  }
//+------------------------------------------------------------------+

 

 
mohsenvix: I need a code that  if price was higher than the open buy position to close position(for buy mode)

Babel. What price was higher? What closed position? If you can't post a concrete question, you can't code it.
learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.