Placing Pending Orders - page 2

 
barnacle7:

Thanks Raptor UK and Lema for your assistance, I changed the cylce "for" as per the code attached but  only 1 pending order is comming through rather then 3 pending orders .I would like to have 3 pending  orders each incremented by 20pips and as 1pending order goes to market another pending order opens maintaining a minimum of 3 pending orders until all orders are closed.

I have tried changing in the cycle "for" ipend<=5 to 1 or and even to 10. But still I only recevie 1 pending order. Is anyone aware how I can acheive this ?

Your loop is still wrong,  read this:  https://www.mql5.com/en/forum/122530/page4#758066
 

Thanks for the link to look at , I am trying to open pending trades. I would like to have  3 pending trades pending at any time even though there is only 1 open trade to begin with.

I would then like to have each pending orders entry price to be 20pips greater then the preceeding pending order.

When I looked at the link #758066 is that only suitable for closing  open and Pending orders, or is it also suitable for opening Pending orders ?, as I am trying to open Pending orders ?

I tried that code ( "for(int ipend=OrdersTotal()-1 ; ipend>=0; ipend--) ") and it continued to generate pending orders but didn't stop. So I wondered if it is suitable for opening pending orders ?

 

Yes, I will change the orderselect you mentioned ,

Thanks 

 

 
barnacle7:

Thanks for the link to look at , I am trying to open pending trades. I would like to have  3 pending trades pending at any time even though there is only 1 open trade to begin with.

I would then like to have each pending orders entry price to be 20pips greater then the preceeding pending order.

When I looked at the link #758066 is that only suitable for closing  open and Pending orders, or is it also suitable for opening Pending orders ?, as I am trying to open Pending orders ?

I tried that code ( "for(int ipend=OrdersTotal()-1 ; ipend>=0; ipend--) ") and it continued to generate pending orders but didn't stop. So I wondered if it is suitable for opening pending orders ?

It's just a for loop,  what determines if it's suitable or not is how you use it,  it has nothing to do with opening orders, pending or otherwise,  it's just a loop. 
 

barnacle7:

 

I tried that code ( "for(int ipend=OrdersTotal()-1 ; ipend>=0; ipend--) ") and it continued to generate pending orders but didn't stop. So I wondered if it is suitable for opening pending orders ?


Look to what i wrote before ......

 deVries:

It goes wrong when you open new trades while you still checking the open trades....

First checking trades has to be done with checking OrdersTotal()    //can't do it with OrderType

If there is one buy open and not right pending buy amount trades open then after you have done the loop you can place them not inside the loop

Also for sell trades  .....

Check your open trades and then look if it is needed to open new pending or manage the trades you have.... 

 
 

You said  "I was trying to have 3 pending trades open Short/ Long each Entry price incremented  by 25pips."

 

and  "I would like to have 3 pending  orders each incremented by 20pips and as 1pending order goes to market another pending order opens maintaining a minimum of 3 pending orders until all orders are closed." 

 

all orders will never be closed because as soon as one pending order becomes a trade another pending order is opened.

I'm not clear what you are trying to do,  are you ? 

 

Thanks, devries this block of code is outside the loop for the open trades and RaptorUK for your assitance ,

This is the structure I am trying to achieve and the updated code below,

(without this block of code the EA Opens ,closes trades and activates trailing stops without issue)

What I am trying to do is have pending orders participate in the EA;

  • If Buy order is triggered (Opens at market), then send 3 pending orders each pending orders opening price is 20 pips higher then the previous order.

eg: Buy order triggered :Buy EURUSD @1.03250 (Market order)

  •  then place 3 pending orders: Pending order 1: BuyStop ,Buy Eurusd @ 1.03450

                                                     "       "          2: Buystop, Buy Eurusd @ 1.03650

                                                    "        "          3.BuyStop, Buy Eurusd @ 1.03850

  •  then , Ordermodify ,add  to the Pending orders stop Losses.

When a pending order is triggered and becomes a open trade then another pending order is opened and it Stop loss is added.

Maintaining a max of 3pending orders at any time.

  • When Close criteria is meet, Close all open "Buy orders" and all "pending orders".

  • "No further trades until next Buy or sell criteria is meet to open a market order."
  • Short positions: Same as above, but for short positons.

 

Current issues: 1/ Pending orders don't open at 20pip increment of the previous prending orders open Price. (Only the 1st pending order is opening 20pips from the Buy order submited at market and the susequent pending orders are the same as the 1st pending order ).

                       2/ Modified Stop loss for each of the pending orders is only calculating from the Buy order submitted at markets "OpenPrice" ? 

                  3/   The pending orders continue to come through even though no pending orders have been triggered, I have in my "order Accounting" Total 8 trades. This stops the pending orders but as it keeps cycling I get the "Alert" which is Alerting more then  8 orders  are  opened  and it is continuing to try and open more.  

Any assistance is appreciated. Thanks 

 

 

//     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()+ (Point*20)*10,2,00,00,"  ",magicnoa); 
      Alert("Pending Order Opened ");
      }    
       
     
     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
Reason: