place just one pending order

[Deleted]  

Hola.

Please who can i place one and just one pending order (buy limit or sell limit) when an order is closed(buy or sell) withe the open price of this order closed.

The problem that i have is that i m wrote a code but when executing in program my EA place more thane one order.

 int cnt,hs = OrdersHistoryTotal();
      for(cnt=hs-1;cnt<=0;cnt--)      
      {   
         if(OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY))
         
            if(OrderMagicNumber()== Num  && OrderSymbol()==Symbol())
           
            if(TimeCurrent()==OrderCloseTime())   // i think that this my error in using this condition
            {
                    if(OrderType()==OP_SELL )
                    { 
                    BPrice=OrderOpenPrice();
                    int t=OrderSend(Symbol(),OP_BUYSLIMIT,lotissma,BPrice,3,0,BTP,"b_rs",Num,0,Green); break;
                    if(t<0) Print("BS",GetLastError(),"ticket",t);
}
                    if(OrderType()==OP_BUY)
                    { 
                     SPrice=OrderOpenPrice();
                     int tu=OrderSend(Symbol(),OP_SELLLIMIT,lotissma,SPrice,3,0,STP,"s_rs",Num,0,OliveDrab);  break;
                     if(tu<0) Print("SS",GetLastError(),"ticket",tu);
                    }
           }
     }
qjol  
   for (int i = 0; i < OrdersTotal(); i++)
      {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol() && OrderMagicNumber()== Num && OrderType() >= 2)
         {
         return(0);
         }
      }
[Deleted]  
qjol:


i can't understand what you mean's withe this code??
qjol  
this code is checking if a pending order exist, if there is one, then, the EA does nothing
[Deleted]  
qjol:
qjol:
this code is checking if a pending order exist, if there is one, then, the EA does nothing

THANK YOU.FOR YOUR REPLAY,BUT IN MY EA I HAVE MORE THAN ONE PENDING ORDER WITHE DIFERENT PRICE SO I WANT TO ADD ANOTHER PENDING ORDER WITH PRICE OF CLOSING ORDER.

qjol  
izmnaari:

i m wrote a code but when executing in program my EA place more thane one order.

this is what u wrote & i gave u the solution

can u be more specific what r u trying to accomplish

William Roeder  
 if(TimeCurrent()==OrderCloseTime())   // i think that this my error in using this condition

OrderCloseTime will be when the order closed. It will never be the time right now.

Go through open orders and find your buys and sells.

Go though the history and find the last buy or sell.

Always test return codes including orderSelect.

bool buySet = false,
     sellSet= false;
    for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
        OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
    &&  OrderMagicNumber()  == magic.number             // my magic number
    &&  OrderSymbol()       == Symbol()                 // and my pair.
    ){
       if (Direction( OrderType() ) > 0)  buySet = true;
       else                              sellSet = true;
    }
double buyPrice  = 0,
       sellPrice = 0;
    datetime lastClose = 0;
    for(int pos=0; pos < OrdersHistoryTotal(); pos++) if (
        OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY)   // Only orders w/
    &&  OrderCloseTime()    > lastClose                 // not yet processed,
    &&  OrderMagicNumber()  == magic.number             // my magic number
    &&  OrderSymbol()       == Symbol()                 // and my pair.
    &&  OrderType()         <= OP_SELL // Avoid cr/bal forum.mql4.com/32363#325360
    ){
        lastClose = OrderCloseTime();
       if (Direction( OrderType() ) > ) buyPrice  = OrderOpenPrice();
       else                             sellPrice = OrderOpenPrice();
    }
if (!buySet){
   if (buyPrice == 0) // No buy history, no buy open, no buy pending...
   //open your buy
}
if (!sellSet)...
:
double  Direction(int op_xxx){  return( 1. - 2. * (op_xxx%2) );                }