Order Modify of Pending order not modifying

 

When the Buy criteria is meet a Market order is trigered and the Market orders SL and TP is added. Then a BuyStop pending order is placed .

The BuyStop pending order should also have the stop loss modified  as soon as it is placed but it doesn't modify after it is placed.

i can't see where in the code below that is causing the problem, any assistance would be great. Thanks 

 

 

   //Counting orders   
  
  for (ckorders=1; ckorders<OrdersTotal(); ckorders--){  //a
      if(OrderSelect(ckorders,SELECT_BY_POS)==true) {   //b   
     
     totorders=OrdersTotal();
     Alert("ttlorders no: ",totorders,Digits);
    
    if (OrderType() == OP_BUYSTOP &&
       OrderMagicNumber()==magicnoa && 
       OrderSymbol() == Symb){            
                   
      openbuyorders++;
      pendb= openbuyorders;
      Alert("OpnBuystop no:",openbuyorders,Digits);
      Alert("Pending Orders No.",totalpend,Digits);
      return(pendb);  
         }
         
    if(OrderType() == OP_SELLSTOP &&
    OrderMagicNumber()==magicnoa && 
    OrderSymbol() == Symb){ 
     
      opensellorders++;
        
      pends= opensellorders;
      totalpend=openbuyorders + opensellorders;
      Alert("opnSellstop no:" , opensellorders,Digits);
      Alert("Pending Orders No.",totalpend,Digits);
         return(pends);
           }
                
         }   //a
       }    //b
    
    


   //Placing Pending orders
	    
     if( pendingorders >0 )   {            //1
   
   
     for(int ipend =OrdersTotal()-1; ipend>=0 ; ipend--) {    //2
     if(OrderSelect(ipend,SELECT_BY_POS))  {    //3   
     
      
     if(OrderType()== OP_BUY &&
      OrderMagicNumber()==magicnoa && 
     OrderSymbol() == Symb) {      
    
     OrderSend(Symb,OP_BUYSTOP,Lts,OrderOpenPrice()+(20*Point)*10,2,00,00,"  ",magicnoa); 
     Alert("Pending Order Opened order no. ");
            
      }         
   
   
   SLP= OrderOpenPrice() - New_Stop(pendingsl)*Point;   
   RefreshRates();  
   
   
   
    if(OrderType() == OP_BUYSTOP &&    
     OrderMagicNumber()==magicnoa && 
     OrderSymbol() == Symb){     //5
         
      if(Ticket < 0)   
         
            {                    
          Alert ("OrderSend failed",GetLastError());
          }                 
        else                                                
        {            //6                                  
        if(!OrderSelect(Ticket,SELECT_BY_TICKET))      
       
        {
               Alert("OrderSelect failed: ",GetLastError());
         }   
         else
         {     //7
           if (!OrderModify(OrderTicket(),OrderOpenPrice(),SLP,00,0))
           {
         Alert("OrderModify Failed",GetLastError());  
                    
            
              }             
            }     //5
          }      //6              
        }     //7      
 
 for (ckorders=1; ckorders<OrdersTotal(); ckorders--){  //a       <== ??  IS THIS RIGHT ??
      if(OrderSelect(ckorders,SELECT_BY_POS)==true) {   //b   
     
     totorders=OrdersTotal();
     Alert("ttlorders no: ",totorders,Digits);            //       <== WHAT IS THIS FOR INFORMATION ?? HOW MANY ALERTS DO YOU LIKE
    
    if (OrderType() == OP_BUYSTOP &&
       OrderMagicNumber()==magicnoa && 
       OrderSymbol() == Symb){            
                   
      openbuyorders++;
      pendb= openbuyorders;
      Alert("OpnBuystop no:",openbuyorders,Digits);     //??  INSIDE THE LOOP ??
      Alert("Pending Orders No.",totalpend,Digits);     //??  
      //return(pendb); <<==== ??
         }
         
    if(OrderType() == OP_SELLSTOP &&
    OrderMagicNumber()==magicnoa && 
    OrderSymbol() == Symb){ 
     
      opensellorders++;
        
      pends= opensellorders;
      //   totalpend=openbuyorders + opensellorders;   <<====   ???  what if last pending buystop order
      Alert("opnSellstop no:" , opensellorders,Digits);   //??  INSIDE THE LOOP ??
      Alert("Pending Orders No.",totalpend,Digits);      //??  
      //   return(pends);  <<==== ??
           }
         }   //a       
       }   //b
 totalpend=openbuyorders + opensellorders;   //ALLERT INFORMATION AFTER LOOP

Difficult ???   Programming ??    

 
barnacle7:

 

When the Buy criteria is meet a Market order is trigered and the Market orders SL and TP is added. Then a BuyStop pending order is placed .

The BuyStop pending order should also have the stop loss modified  as soon as it is placed but it doesn't modify after it is placed.

i can't see where in the code below that is causing the problem, any assistance would be great. Thanks 

Have you checked your for loop ?

for (ckorders=1; ckorders<OrdersTotal(); ckorders--){  //a

 you start at 1 and decrement to 0 then -1 at which point your OrderSelect() will fail . . .  then -2 etc,  

Try this . . .

for (ckorders = OrdersTotal() - 1; ckorders >= 0; ckorders--){  //a

Why are you returning and exiting the function ?

return(pendb);  
 

I added A)  to count the pending orders,so that I can control the number of pending orders open.

I originally put in " return(pendb); " so that I could get the number of pending orders open and then pass it to code which would maintain 1 or 2 Buystop pending orders. (that was the idea behind the "r eturn(pendb) ".

With it changed as per B) the pending Buystop orders continue to come through , with the counter there now to count the orders, how can I maintain 1 or 2 Buystop pending orders ?

Thanks 

  

A)
for (ckorders=1; ckorders<OrdersTotal(); ckorders--){  //a                
      if(OrderSelect(ckorders,SELECT_BY_POS)==true) {   //b   
     
     totorders=OrdersTotal();
     Alert("ttlorders no: ",totorders,Digits);
    
    if (OrderType() == OP_BUYSTOP &&
       OrderMagicNumber()==magicnoa && 
       OrderSymbol() == Symb){            
                   
      openbuyorders++;
      pendb= openbuyorders;
      Alert("OpnBuystop no:",openbuyorders,Digits);
      Alert("Pending Orders No.",totalpend,Digits);
      return(pendb);  
         }

B)
//**Changed it to this and the Pending orders stoploss is modified.But then the pending orders don't stop.

for (ckorders=OrdersTotal()-1; ckorders>=0; ckorders--){  //a
      if(OrderSelect(ckorders,SELECT_BY_POS)==true) {   //b   

  /*return(pendb);  */    and Deleted the return. 
 
barnacle7:

I added A)  to count the pending orders,so that I can control the number of pending orders open.

I originally put in " return(pendb); " so that I could get the number of pending orders open and then pass it to code which would maintain 1 or 2 Buystop pending orders. (that was the idea behind the "r eturn(pendb) ". 

What function is this code in ?  what function are you passing the return value back to ?
 
barnacle7:


With it changed as per B) the pending Buystop orders continue to come through , with the counter there now to count the orders, how can I maintain 1 or 2 Buystop pending orders ?


Maybe . . .

if(pendb < 2) OrderSend(Symb,OP_BUYSTOP,Lts,OrderOpenPrice()+(20*Point)*10,2,00,00,"  ",magicnoa); 
 
RaptorUK:

Maybe . . .

 

 having the return(pendb) ;  1 pending order opens but the  stoploss isn't modified.

What I would like to do is as Buystop pending orders are triggered to open trades.  Is to replenish and maintain 1 to 2 Buystop pending orders. Once the the criteria to close the open Buy order is meet then all open Buy orders and Buystop pending orders are closed .

This is all I want to acheive for the pending orders. Is there a guide I can follow or are you able to tell me if what I am doing is in the right direction and how to move forward ?

Thanks   

 
RaptorUK:
What function is this code in ?  what function are you passing the return value back to ?


? ?
 
RaptorUK:

? ?

I've been trying to work things out from the book etc, I would say the  counter needs to go outside the Parenthisis of "Create Pending orders" . Using the Return (Function),  return the value back to the variable (pendb) or (pends) to evaluate if additional pending orders can be placed. 

 I have Alerts to note the count of eg: SellStopPending Orders.  (Using the "Counter orders" in the code below) . The numbers appear as 15 , 25 , 15 , 25 , 35 , 15, 25 , 35 , 45 from the Alert. (Then I stopped the EA). I thought it would have been counting as 1 , 2 , 3 , 4 etc.. for eg: 1 Pending order, 2 Pending orders etc..

Is it correct that it is showing 15, 25 etc... ?   as I have place in the code below " if(Pendb < 2) " , it won't work ,Correct ? How can I get it so it is correct if it isn't correct ?

Thanks, for your assistance. 

 

 

 

 //     Create Pending Orders          
     
   
   
    
     if( pendingorders >0 )   {            //1
   
   
    
      
     if(OrderType()== OP_BUY &&
      OrderMagicNumber()==magicnoa && 
     OrderSymbol() == Symb && pendb < 2) {                         ................................value is returned here
       
     OrderSend(Symb,OP_BUYSTOP,Lts,OrderOpenPrice()+(20*Point)*10,2,00,00,"  ",magicnoa); 
     Alert("Pending Order Opened order no. ");
         
  
      }         
    SLP= OrderOpenPrice() - New_Stop(pendingsl)*Point;
    RefreshRates();
      
    if(OrderType() == OP_BUYSTOP &&    
     OrderMagicNumber()==magicnoa && 
     OrderSymbol() == Symb){     //5
    
      SLP= OrderOpenPrice() - New_Stop(pendingsl)*Point; 
      Alert("SLP no :",SLP,Digits);
        
     
        
      if(Ticket < 0)   
         
            {                    
          Alert ("OrderSend failed",GetLastError());
          }                 
        else                                                
        {            //6                                  
        if(!OrderSelect(Ticket,SELECT_BY_TICKET))      
       
        {
               Alert("OrderSelect failed: ",GetLastError());
         }   
         else
         {     //7
           if (!OrderModify(OrderTicket(),OrderOpenPrice(),SLP,00,0))
           {
         Alert("OrderModify Failed",GetLastError());  
                    
            
              }             
            }     //5
          }      //6              
        }     //7      
    
    if(OrderType()== OP_SELL &&
    OrderMagicNumber()==magicnoa && 
    OrderSymbol() == Symb){ 
   
    OrderSend(Symb,OP_SELLSTOP,Lts,OrderOpenPrice() - (Point*20)*10,2,00,00,"  ",magicnoa);
              
             
    Alert("Pending Order opened");
        }
    else
        {
    Alert("Pending Order Failed" ,GetLastError());
    }
     SLP2= OrderOpenPrice() + New_Stop(pendingsl2)*Point; 
     RefreshRates();
       
       if(OrderType() == OP_SELLSTOP &&    
     OrderMagicNumber()==magicnoa && 
     OrderSymbol() == Symb && pends < 2){     //8   ...............................Value is returned here
     if(Ticket < 0)   
         
            {                    
          Alert ("OrderSend failed",GetLastError());
          }                 
        else 
        {            //9
        if(!OrderSelect(Ticket,SELECT_BY_TICKET))    
       
        {
               Alert("OrderSelect failed: ",GetLastError());
         }   
         else
         {     //10
           if (!OrderModify(OrderTicket(),OrderOpenPrice(),SLP2,00,0))
           {
         Alert("OrderModify Failed",GetLastError());   
          }    
       
            
                    
                  
               }      //1
          }        //8       
        }        //9     
       }       //10
//---------------------------------------------------------------------------------
  //Counting orders                                                              .........Placed the counter here out of Parenthisis of the "Creating Pending Orders"
   
  
  for (ckorders=OrdersTotal()-1; ckorders>=0; ckorders--){  //a
      if(OrderSelect(ckorders,SELECT_BY_POS)==true) {   //b   
     
     totorders=OrdersTotal();
     Alert("ttlorders no: ",totorders,Digits);
    
    if (OrderType() == OP_BUYSTOP &&
       OrderMagicNumber()==magicnoa && 
       OrderSymbol() == Symb){            
                   
      openbuyorders++;
      pendb= openbuyorders;
      Alert("OpnBuystop no:",openbuyorders,Digits);
      Alert("Pending Orders No.",totalpend,Digits);
      return(pendb);  
         }
         
    if(OrderType() == OP_SELLSTOP &&
    OrderMagicNumber()==magicnoa && 
    OrderSymbol() == Symb){ 
     
      opensellorders++;
        
      pends= opensellorders;
      totalpend=openbuyorders + opensellorders;
      Alert("opnSellstop no:" , opensellorders,Digits);
      Alert("Pending Orders No.",totalpend,Digits);
         return(pends);
           }
                
         }   //a
       }    //b        
 
barnacle7:

I've been trying to work things out from the book etc, I would say the  counter needs to go outside the Parenthisis of "Create Pending orders" . Using the Return (Function),  return the value back to the variable (pendb) or (pends) to evaluate if additional pending orders can be placed. 

 I have Alerts to note the count of eg: SellStopPending Orders.  (Using the "Counter orders" in the code below) . The numbers appear as 15 , 25 , 15 , 25 , 35 , 15, 25 , 35 , 45 from the Alert. (Then I stopped the EA). I thought it would have been counting as 1 , 2 , 3 , 4 etc.. for eg: 1 Pending order, 2 Pending orders etc..

Is it correct that it is showing 15, 25 etc... ?   as I have place in the code below " if(Pendb < 2) " , it won't work ,Correct ? How can I get it so it is correct if it isn't correct ?

Thanks, for your assistance.  


  ? ?

totorders=OrdersTotal();
Alert("ttlorders no: ",totorders,Digits);            //       <== WHAT IS THIS FOR INFORMATION ?? HOW MANY ALERTS DO YOU LIKE

 Difficult ???   Programming ??       HOW many Help do you need ???     Why Allerting in Loop ???   

totorders=OrdersTotal();
Alert("ttlorders no: ",totorders,"  ",Digits);            //       <== WHAT IS THIS FOR INFORMATION ?? HOW MANY ALERTS DO YOU LIKE
 
barnacle7:

I've been trying to work things out from the book etc, I would say the  counter needs to go outside the Parenthisis of "Create Pending orders" . Using the Return (Function),  return the value back to the variable (pendb) or (pends) to evaluate if additional pending orders can be placed.  

I think you have a big misunderstanding of what return() does and when it should be used.
Reason: