problem with order open price

 
hi guys ..i have some troubles with this block of codes .. 
int init() {

////////////////////////////////////////////////////////////////////////////
if(MarketInfo(Symbol(), MODE_DIGITS)==3||MarketInfo(Symbol(), MODE_DIGITS)==5)
mypoint=10;
else mypoint=1; 
pte=Point*mypoint;

   return (0);
///////////////////////////////////////////////////////////////////////////
}
int start()
  {
  
  
  
  if (TotalOrderCount() >0) return(0);

 Buy1 = OrderSend(Symbol(),OP_BUY,lot,Ask,Slippage,0,Ask+TP*pte,"",MagicNumber,0,Green);
 
 
 if(OrdersTotal()>0){
for(pos=OrdersTotal();pos>=0;pos--){
double resuet=OrderSelect(pos,SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_BUY && OrderSymbol()==Symbol()){
      
    double OP_price = OrderOpenPrice();
  
  
         if( Buy1 >0 && (Bid < (OP_price-20*pte)) )  
          Alert("Open price " , OP_price  ); 
            
 //S = OrderSend(Symbol(),OP_SELL,2*lot,Bid,Slippage,0,Bid-TP*pte,"",MagicNumber,0,Red);
 

}}}
 
  }
  
  return (0);
    }
 

i wanna open a sell order after 20 pip of the opening price of a buy order ..after checking out the value of the OrderOpenPrice() its correct .. 

can u guys please take a look and see where im missing it ?? thank  u in advance  

 
  if (TotalOrderCount() >0) return(0);

Assuming that this function counts open orders

If there is at least 1 open order, none of the following code will be executed

Please use correct English, if you mean "you" write "you", not "u".

Not all posters are native English speakers and may not understand such abbreviations.

 
 ok i used this block to open one order only ( if i remove it ..it open an infinity of the same order) .. if you have a better way to do it please show me ..
 int orders=0; 
for (int i=0; i<OrdersTotal(); i++){ 
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) 
if(OrderSymbol()==Symbol()) 
orders++; 
      }
  if(orders==0)
{ 
 
Amin0xy:
 ok i used this block to open one order only ( if i remove it ..it open an infinity of the same order) .. if you have a better way to do it please show me ..
Check the OrderType() in your loop.
 
thank you GumRai for your notice ..its working now....but the serious problem still remaining
 double OP_price = OrderOpenPrice();
  
  
         if( Buy1 >0 && (Bid < (OP_price-20*pte)) )  
          Alert("Open price " , OP_price  ); 
            
 //S = OrderSend(Symbol(),OP_SELL,2*lot,Bid,Slippage,0,Bid-TP*pte,"",MagicNumber,0,Red);

 how i gone make this condition right ?  i want it to open a new order after it hit 20 pip under the order open price ...please can you help me with that ? 

thank you for your help  

 
Amin0xy:
thank you GumRai for your notice ..its working now....but the serious problem still remaining

 how i gone make this condition right ?  i want it to open a new order after it hit 20 pip under the order open price ...please can you help me with that ? 

thank you for your help  

What is the problem?
 

the problem is  : the expert does not respect this condition 

 

if( Buy1 >0 && (Bid < (OP_price-20*pte)) )  

 i even tried serval things like :

 using this form

OP_price-Bid >= 20*pte

 

 or even tried to select  the order : 

Buy1 = OrderSend(Symbol(),OP_BUY,lot,Ask,Slippage,0,Ask+TP*pte,"",MagicNumber,0,Green);
 
 /////////////////////////////////////////////////////////////////////////////////////
 if(OrdersTotal()>0){
for(pos=OrdersTotal();pos>=0;pos--){
double resuet=OrderSelect(pos,SELECT_BY_POS,MODE_TRADES);
if(OrderType()==OP_BUY && OrderSymbol()==Symbol()){
      
    double OP_price = OrderOpenPrice();
      
    if(Buy1>0) 
    if(OrderSelect(Buy1,SELECT_BY_TICKET,MODE_TRADES)){   // here i tried to select the order ..
           
         if( (OP_price-Bid > 20*pte) ){   

          Alert("Open price " , OP_price  ); 
         
 
 //S = OrderSend(Symbol(),OP_SELL,2*lot,Bid,Slippage,0,Bid-TP*pte,"",MagicNumber,0,Red);

 

 but always the same result .. no application  of the "Alert" or the "S=OrderSend(Symbol(),OP_SELL,...."

 

Why are you looping through the orders when you know the ticket number?

   B=OrderSend(Symbol(),OP_BUY,lot,Ask,Slippage,0,Ask+TP*pte,"",MagicNumber,0,Green);

/////////////////////////////////////////////////////////////////////////////////////
   if(B>0)
     {
      if(OrderSelect(B,SELECT_BY_TICKET))
        {   // here i tried to select the order ..

         if((OrderOpenPrice()-Bid>20*pte))
           {

            Alert("Open price ",OrderOpenPrice());

            //S = OrderSend(Symbol(),OP_SELL,2*lot,Bid,Slippage,0,Bid-TP*pte,"",MagicNumber,0,Red);
           }
        }
     }

Assuming that B is a globally declared variable. If it is locally declared, then it will not have kept the correct value for the following ticks