Flickering StopLoss and Take Profit after Initially Modifying -Sell Limit

 

Every thing works except for the SellLimits , Stop loss and Take Profit which flickers.

I am placing a at MKT "Sell order" and then a 1x Sell on Stop order and a 1x Sell at Limit order. Being an ECN Boiker I have to do order Modify to modify stop Loss and Takeprofit on each order.

The problem is with the "Sell Limit order" the stop Loss and the Take Profit flick back and forth ;

Below shows how the "Sell Limit " Stop Loss and Take Profit is changing back and forth.

The Sell Limit Stop Loss and Take Profit are changing fom the correct SL and TP to the "Sell Stops" SL and TP . and then back again.

The ODD thing is that the Buy orders work using same code.

Has anyone else experienced this . I have attached my code also if any one can see where the Thanks

2013.03.11 09:10:45New 1 EA EURUSD,M15: modify #19746439 sell limit 0.10 EURUSD at 1.30192 sl: 1.30792 tp: 1.29542 ok : this is correct

2013.03.11 09:10:45New 1 EA EURUSD,M15: modify #19746439 sell limit 0.10 EURUSD at 1.30192 sl: 1.30292 tp: 1.29292 ok : This is incorrect (It is the same as the Sell "Stop Stop" Loss and Take Profit)

2013.03.11 09:10:44New 1 EA EURUSD,M15: modify #19746439 sell limit 0.10 EURUSD at 1.30192 sl: 1.30792 tp: 1.29542 ok :and Back to "this correct SL and TP".

2013.03.11 09:10:43New 1 EA EURUSD,M15: modify #19746439 sell limit 0.10 EURUSD at 1.30192 sl: 1.30292 tp: 1.29292 ok

2013.03.11 09:10:41New 1 EA EURUSD,M15: modify #19746439 sell limit 0.10 EURUSD at 1.30192 sl: 1.30792 tp: 1.29542 ok

 
barnacle7:


2013.03.11 09:10:45New 1 EA EURUSD,M15: modify #19746439 sell limit 0.10 EURUSD at 1.30192 sl: 1.30292 tp: 1.29292 ok : This is incorrect (It is the same as the Sell "Stop Stop" Loss and Take Profit)

2013.03.11 09:10:44New 1 EA EURUSD,M15: modify #19746439 sell limit 0.10 EURUSD at 1.30192 sl: 1.30792 tp: 1.29542 ok :and Back to "this correct SL and TP".

This is incorrect (It is the same as the Sell "Stop Stop" Loss and Take Profit)    select correct OrderType()
 
deVries:

This is incorrect (It is the same as the Sell "Stop Stop" Loss and Take Profit)    select correct OrderType()

 

Thanks deVries, Yes I  had the OrderType() , when I print it recognises it as a SellLimit "3", but it still continues to flicker.

There is code above it (In the fille attached in previous post) where the Sell stop order is placed and the modify tries to occur although since the Sell limit pending order is placed it stops it from modifying the Sell Stop.

If I remove this code for the Sell Stop Modify code above it stops the flickering. I dont' understand why it is causing the Sell Limit to flicker. As both have the appropriate Ordertype() selected to modify each pending orders SL and TP.

  

 

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

      if(OrderType() == OP_SELLLIMIT &&
      OrderMagicNumber()==magicnoa && 
      OrderSymbol() == Symb){   //e   
     
      openselllimitorders++;     
      pendsl= openselllimitorders;
   
           }  //e             
  
      if(OrderType()== OP_SELL &&
      OrderMagicNumber()==magicnoa && 
      OrderSymbol() == Symb && pendsl < 1){ 
    
      OrderSend(Symb,OP_SELLLIMIT,Lts,OrderOpenPrice() + (20*Point)*10,5,00,00,"  ",magicnoa);       
                
        } 
   if(OrderType() == OP_SELLLIMIT &&    
       OrderMagicNumber()==magicnoa && 
       OrderSymbol() == Symb ){     //8   
       SLPSL= OrderOpenPrice() + New_Stop(pendingsl2)*Point;         
    
       TP5=OrderOpenPrice() - New_Stop(TakeProfit)*Point; 
    
     if(Ticket < 0)   
         
            {                    
          Alert ("OrderSend failed",GetLastError());
          }                 
        else 
        {            //9
        if(!OrderSelect(Ticket,SELECT_BY_TICKET))    
       
        {
               Alert("OrderSelect failed: ",GetLastError());
         }   
         else
         {     //10
           OrderModify(OrderTicket(),OrderOpenPrice(),SLPSL,TP5,0);
                    Print("OrderType",OrderType(),Digits);                                        
                    
                         }        //8       
                        }        //9     
                       }       //10        
                      }   //a
                     }   //b
                   }  //2   

nd then tried to select the 

 
barnacle7:

Every thing works except for the SellLimits , Stop loss and Take Profit which flickers.

I am placing a at MKT "Sell order" and then a 1x Sell on Stop order and a 1x Sell at Limit order. Being an ECN Boiker I have to do order Modify to modify stop Loss and Takeprofit on each order.

The problem is with the "Sell Limit order" the stop Loss and the Take Profit flick back and forth ;

Read this and use it: What are Function return values ? How do I use them ?

 

Where does Ticket come from ?

      if(OrderType()== OP_BUY &&                                          
      OrderMagicNumber()==magicnoa &&
      OrderSymbol()  == Symb && pendb < 1) {   
          
     OrderSend(Symb,OP_BUYSTOP,Lts,OrderOpenPrice() + (20*Point)*10,5,00,00,"  ",magicnoa);      //Place Buystop (Pending orders)  //  check the return value
                  
    if(OrderType() == OP_BUYSTOP &&    
     OrderMagicNumber()==magicnoa && 
     OrderSymbol() == Symb){     //5
    
     SLP= OrderOpenPrice() - New_Stop(pendingsl)*Point; 
              
      TP2= OrderOpenPrice() + New_Stop(TakeProfit)*Point; 
        
      if(Ticket < 0)                                      //Modify Buy stop (Pending order)   ??  which Ticket ? ?
         {                    
          Alert ("OrderSend failed",GetLastError());
          }                 
      else                                                
         {            //6                                  
         if(!OrderSelect(Ticket,SELECT_BY_TICKET))      
            {
             Alert("OrderSelect failed: ",GetLastError());
            }   
         else
            {     //7
            if(! OrderModify(OrderTicket(),OrderOpenPrice(),SLP,TP2,00))
           
 
RaptorUK:

Read this and use it: What are Function return values ? How do I use them ?

 

Where does Ticket come from ?

 

 

  int Ticket=OrderTicket(); 

 I checked the return on all the "Order sends " they all return the ticket .

The sell limit keeps flickering and Modifying, Iam still unsure why. (It is all working except for the flickering)

Any further suggestion are appreciated. 

 Thanks ,  

(Please disregard The "Break "and a "Parenthesis" under the Sellstop code . It has crept in there by accident.)

          }     //a
         }     //b                   
        }   //1                          
       
       break   :Please disregard ,
       }        ""    ""     ""
 

What good is it to open trades in a loop 

Finish your loop before you open a new trade !!!

You make errors this way

.. 

and don't say stupid things you didn't check OrderSend( ) everywhere see.... 

         }  //e             
  
      if(OrderType()== OP_SELL &&
      OrderMagicNumber()==magicnoa && 
      OrderSymbol() == Symb && pendsl < 1){ 
    
      OrderSend(Symb,OP_SELLLIMIT,Lts,OrderOpenPrice() + (20*Point)*10,5,00,00,"  ",magicnoa);       
                                               //????  Where is that OrderCheck ??
        } 
   if(OrderType() == OP_SELLLIMIT &&    
 
barnacle7:

 I checked the return on all the "Order sends " they all return the ticket .

If you look at the code I posted (copied from your attachment)  you can see that between the OrderSend()  (OP_BUYSTOP)  and the attempt to   "Modify Buy stop (Pending order)"   you don't get the ticket number for the BuyStop . . .  so you are trying to modify the wrong ticket . . .

 

Check the return value from the OrderSend(),  if it suggests that the OrderSend() has worked (return value > 0)  then,  and only then,  attempt the OrderModify() . . .  something like this

      if(OrderType()== OP_BUY &&                                          
      OrderMagicNumber()==magicnoa &&
      OrderSymbol()  == Symb && pendb < 1) {   
          
     if(OrderSend(Symb,OP_BUYSTOP,Lts,OrderOpenPrice() + (20*Point)*10,5,00,00,"  ",magicnoa) > 0)      //Place Buystop (Pending orders) 
        {     //5
        SLP= OrderOpenPrice() - New_Stop(pendingsl)*Point; 
        TP2= OrderOpenPrice() + New_Stop(TakeProfit)*Point; 

        if(!OrderSelect(Ticket,SELECT_BY_TICKET))      
            {
             Alert("OrderSelect failed: ",GetLastError());
            }   
         else
            {     //7
            if(! OrderModify(OrderTicket(),OrderOpenPrice(),SLP,TP2,00))  //Modify Buy stop (Pending order)
               {
               Print("OrderModify failed, error# ", GetLastError(), " SL: ", SLP, " TP: ", TP2 );
               }
            }
         }  // end of 5
      else                                      
         {                    
          Alert ("OrderSend failed",GetLastError());
          }                 
Reason: