Plese Help Why Pending Order Not Delete when outside the range working time

To add comments, please log in or register
muhammad jalal
202
muhammad jalal  

hi, Please help me, i have problem when i want to delete all pending order outside the range working time, my coding not work to delete pending order ,please help for this problem

working time
extern   int      HourStart   = 9;   
extern   int      HourEnd     = 11
 
//-----

if(OrdersTotal()==0)         
   {     
       if(Hour() >= HourStart && Hour() <= HourEnd)
      {
    // send order pending
     SellTicket = OrderSend
    (
      Symbol(),OP_SELLSTOP,Lotsa,Bid-StepPending*SetPoint,3,0, Bid-StepPending*SetPoint-TakeProfit*SetPoint,Comment_,EAMagicNumber,0,Red
     );  
     
       BuyTicket = OrderSend
    (
     Symbol(),OP_BUYSTOP,Lotsa,Ask+StepPending*SetPoint,3,0, Ask+StepPending*SetPoint+TakeProfit*SetPoint,Comment_,EAMagicNumber,0,Blue
    );     
         }}
         //---delete pending order when outside working time
         
        if(OrdersTotal()>1 && Hour() > HourEnd && Hour() < HourStart)         
   {       
          
deletepending();}


//-----
int deletepending()
{
int i,a;
int total = OrdersTotal();
string komentar,par;

for (i=total-1; i >=0; i--)
{
pilih=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if (OrderType()==OP_BUY || OrderType()==OP_SELL)
{
for (a=total-1; a >=0; a--)
{
pilih=OrderSelect(a,SELECT_BY_POS,MODE_TRADES);
komentar=OrderComment();
par=StringSubstr(komentar,0,6); 
if(OrderType()==OP_SELLSTOP)// && komentar==Symbol())
{
pilih=OrderDelete(OrderTicket());
Print("Deleting SELLSTOP"," Ordertype:",OrderType());
return(1);
}
if(OrderType()==OP_BUYSTOP)// && par==Symbol())
{
pilih=OrderDelete(OrderTicket());
Print("Deleting BUYSTOP"," Ordertype:",OrderType());
return(1);

}
}
}
}
return(0);}

William Roeder
20210
William Roeder  
  1. Do you really expect an answer? We can't see your broken code. There are no mind readers here and our crystal balls are cracked.
  2. In the presence of multiple orders (one EA multiple charts, multiple EAs, manual trading,) while you are waiting for the current operation (closing, deleting, modifying) to complete, any number of other operations on other orders could have concurrently happened and changed the position indexing:
    1. For non-FIFO (US brokers,) (or the EA only opens one order per symbol,) you can simply count down in a position loop, and you won't miss orders. Get in the habit of always counting down.
                Loops and Closing or Deleting Orders - MQL4 and MetaTrader 4 - MQL4 programming forum
      For FIFO (US brokers,) and you (potentially) process multiple orders per symbol, you must count up and on a successful operation, reprocess all positions (set index to -1 before continuing.)
    2. and check OrderSelect in case earlier positions were deleted.
                What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
                Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
    3. and if you (potentially) process multiple orders, must call RefreshRates() after server calls if you want to use the Predefined Variables (Bid/Ask) or OrderClosePrice() instead, on the next order/server call.
To add comments, please log in or register