Order modify Pending Orders ECn broker

 

 I want to place a Market Buy order and then pending orders (Buy Stop), since it is a ecn broker I have to use OrderModify with all orders  to add the stop loss.  

The "Market orders", Stop Loss and TakeProfit is modified, and works well.

But when I try to modify the Pending order it only modifies the stop loss by calculating  from the Market orders "OpenPrice" rather then from the Pending orders (BUY_Stop EntryPrice) . 

eg: 

Buy orders: 

 (Buy) Mkt Entry : order open Price : 1.03255 

Pending order stop Loss :30 pips

Pending order BUY_ Stop Price to Enter: 1.03455  

(The Problem) ,So at the moment the pending Orders stoploss is modified to : 1.02955 ,so it is calculating from the Market orders "Open Price" .

What I want is for it to calculate the Stop Loss from the pending orders Entry price ,So for the  Pending orders stop loss to be 1.03155.

Using Orderopen Price function in the order modify code, does it  recognise it for pending orders ? 

Has anyone else had this issue ? and how can I overcome this issue  ?  Thanks. 

 

 

 if(Ticket < 0) 
         
            {                    
          Alert ("OrderSend failed",GetLastError());
          }                 
        else 
        {         //4
        if(!OrderSelect(Ticket,SELECT_BY_TICKET))
        {
               Alert("OrderSelect failed: ",GetLastError());
         }   
         else
         {         //5  
           if (!OrderModify(OrderTicket(),OrderOpenPrice(),SL,TP,0))
 
barnacle7:

 I want to place a Market Buy order and then pending orders (Buy Stop), since it is a ecn broker I have to use OrderModify with all orders  to add the stop loss.  

The "Market orders", Stop Loss and TakeProfit is modified, and works well.

But when I try to modify the Pending order it only modifies the stop loss by calculating  from the Market orders "OpenPrice" rather then from the Pending orders (BUY_Stop EntryPrice) . 

You don't show where your SL and TP are calculated . . .
 
RaptorUK:
You don't show where your SL and TP are calculated . . .

  //     Create Pending Orders          
   
     SLP= Bid - New_Stop(pendingsl)*Point;   
      SLP2= Ask + New_Stop(pendingsl2)*Point;
      RefreshRates();
  
   
     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. ");
            
      }   
       
        
    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      
    
    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());
    }
       
       
       if(OrderType() == OP_SELLSTOP &&    
     OrderMagicNumber()==magicnoa && 
     OrderSymbol() == Symb){     //8   
     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
            }       //2
          }        //3
         }        //8       
        }        //9     
       }       //10
 
barnacle7:

 


Your code shows 2 calls to OrderModify(),  both calls use SLP2 for the Stop Loss and it is calculated using 

SLP= Bid - New_Stop(pendingsl)*Point;   //Bid on both?

 I see Bid which would be the entry price for a current Sell Market order . . .   I have no idea what the function New_Stop()  does,  you don't show it or what the value of pendings1 is,  I don't see the OrderOpenPrice() for the pending order used anywhere.

 

 SLP (BuyStop) and SLP2 (SellStop)  calculates the stoploss and is passed to the OrderModify .

 

 Orderopenprice() is used in both , Ordersend and the OrderModify  , for both the Buystop and SellStop . 

Thanks 

 

extern double pendingsl = 500;
extern double pendingsl2 =600;


SLP= Bid - New_Stop(pendingsl)*Point;       //BuyStop ,Stop Loss   //Calculate the stop loss 
SLP2= Ask + New_Stop(pendingsl2)*Point;     //Sellstop ,Stop Loss   


// Below is To check Minimum distance

int New_Stop(int Parametr)                      
  {
   int Min_Dist=MarketInfo(Symb,MODE_STOPLEVEL);
   if (Parametr<Min_Dist)                       
     {
      Parametr=Min_Dist;                        
      Alert("Increased distance of stop level.");
     }
   return(Parametr);      
                     
  }
 
barnacle7:

 

 SLP (BuyStop) and SLP2 (SellStop)  calculates the stoploss and is passed to the OrderModify .

  Orderopenprice() is used in both , Ordersend and the OrderModify  , for both the Buystop and SellStop . 

Where is the OrderOpenPrice() of the pending order used in the calculation of the pending order's new SL ?  I don't see it . . .
 
RaptorUK:
Where is the OrderOpenPrice() of the pending order used in the calculation of the pending order's new SL ?  I don't see it . . .

I have added OrderOpenprice() in the SRC at the bottom, and that is now working , Thanks, you make it look so simple, I won't say how long I have been trying different things to get it to work.

I've also been trying to work this out ,I need a switch to turn off the cycle while there is 1 pending order open and turn the cylce on to replenish a new pending order if it is trigered to a market order.

How can I code when pending orders are greater then >= 1 pending stop cycling orders Buystop (which has a Value of 4)   ?  

 I have also tried to code using both Break; as per below and when I couldn't get that to work I tried to use continue; it didn't stop it from cycling either ,How to stop it cycling ?    

thanks 

//To stop the cycle until the pending order needs to be replenished as 1 has a pending order has trigered to a market order.

option1:

 if (!OrderModify(OrderTicket(),OrderOpenPrice(),SLP2,00,0))
           {
         Alert("OrderModify Failed",GetLastError());   
          }    
       
            if(OrderType() ==OP_BUYSTOP || OrderType()OP_SELLSTOP) = 1 ; break;            
                  
               }          //1 
                }       //2
               }        //3
              }        //8       
            }        //9     
           }       //10

option2:
        continue;

 

At the moment the pending continue to stream through. 

 

  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;        // Thanks , Moved from top to here and changed it and it is now calc correctly.
      RefreshRates();  
   
    if(OrderType() == OP_BUYSTOP &&    
     OrderMagicNumber()==magicnoa && 
     OrderSymbol() == Symb){     //5
         
      if(Ticket < 0)   
         
            {                    
          Alert ("OrderSend failed",GetLastError());
 

.

 
barnacle7:

I have added OrderOpenprice() in the SRC at the bottom, and that is now working , Thanks, you make it look so simple, I won't say how long I have been trying different things to get it to work.

I've also been trying to work this out ,I need a switch to turn off the cycle while there is 1 pending order open and turn the cylce on to replenish a new pending order if it is trigered to a market order.

How can I code when pending orders are greater then >= 1 pending stop cycling orders Buystop (which has a Value of 4)   ?   

Do you mean how can you stop placing further pending orders if you already have 1 or more pending orders ?  just count the number of pending orders you already have . . .
Reason: