problem w/ delete condition

 
   for (int i=0; i<OrdersTotal(); i++)  
   {
   OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if (Symbol()==OrderSymbol() && OrderMagicNumber()==MagicNumber && OrderProfit() >= OrderOpenPrice() + movestopto*point)     
      {
         if(OrderType()==OP_BUYSTOP && OrderMagicNumber()==MagicNumber2)
         {     
         OrderDelete(OrderTicket());
         }
         else
         if(OrderType()==OP_SELLSTOP && OrderMagicNumber()==MagicNumber2)
         {     
         OrderDelete( OrderTicket() );
         }
      }
   } 

i have problems w/ the delete condition above, what is wrong?

it shoukd delete pending order if standard order 1 hit the BE movestopto spot

BE = 5;

movestopto = 3;

 
fulltilt:

i have problems w/ the delete condition above, what is wrong?

it shoukd delete pending order if standard order 1 hit the BE movestopto spot

BE = 5;

movestopto = 3;

If your OrderSelect() fails OrderSymbol(), OrderMagicNumber(), OrderProfit(),  OrderOpenPrice()  are all meaningless . . .   as you haven't selected an order.  You might want to check that your OrderSelect() has worked before letting your code continue.

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

Also this is meaningless for two reasons  . . .

OrderProfit() >= OrderOpenPrice()

  . . .  OrderProfit() is not a price it is a value in terms of your account currency . . .  and how can a pending order have a profit ?

 One more thing,  if you are expecting your loop to delete more than one order you need to think again,  read this :  Loops and Closing or Deleting Orders

 

thank You, I will use the delete part as in Your sample

but can I use this one as condition part?

if magic1 hit the  BE movestopto

        int deltotal;
        deltotal=0;
        
        for(int d=0;d<OrdersTotal(); d++)
        {
        if(OrderSelect(d,SELECT_BY_POS,MODE_TRADES))
        if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && OrderProfit() >= OrderOpenPrice() + movestopto*point)
        {
        deltotal++;
        }
        }        

        if (deltotal==1)
        {
        // order delete part
        }
 
fulltilt:

thank You, I will use the delete part as in Your sample

but can I use this one as condition part?

if magic1 hit the  BE movestopto

You can't delete an open order (OP_BUY or OP_SELL)  you can only delete a pending order and a pending order does not have a profit or loss and it isn't yet opened . . . it is pending.

As I said already,  OrderProfit() gives the value in your account currency of how much profit or loss the trade has made . . .  not pips or points. 

 

yes we have 1 pending and 1 standard order

if standard order (magic1) hit movestopto, delete pending order (magic2)

fex:

        int deltotal;
        deltotal=0;
        
        for(int d=0;d<OrdersTotal(); d++)
        {
        if(OrderSelect(d,SELECT_BY_POS,MODE_TRADES))
        if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && OrderProfit() >= OrderOpenPrice() + movestopto*point)
        {
        deltotal++;
        }
        }        

if (deltotal==1)
{

   for(i=OrdersTotal();i>=0;i--)
        {
        OrderSelect(i, SELECT_BY_POS);
        if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber2)
        {
        if(OrderType()==OP_BUYSTOP)   OrderDelete( OrderTicket() );
        if(OrderType()==OP_SELLSTOP)  OrderDelete( OrderTicket() );
        }
        Sleep(1000);
        }

}
 
fulltilt:

yes we have 1 pending and 1 standard order

if standard order (magic1) hit movestopto, delete pending order (magic2)

fex:

OK,  I understand now . . .  you should have said that in your first post.  

Instead of OrderProfit()  use OrderClosePrice()  then you don't have to distinguish between a Buy and Sell.  But what you have written will only work for a Buy,  a Sell that is in profit will always have it's OrderClosePrice() below it's OrderOpenPrice() . . . 
 

sounds good ;-)

I will try adding both condition for Buy&Sell 

are these parts correct ?

OrderClosePrice() >= OrderOpenPrice() + movestopto*point
OrderClosePrice() <= OrderOpenPrice() - movestopto*point
 

Instead you could try something like this . . .   it won't be exactly what you want but it should get you on the right track . . .

int deltotal, Direction;

deltotal=0;
        
for(int d=0;d<OrdersTotal(); d++)
   {
   if(OrderSelect(d,SELECT_BY_POS,MODE_TRADES))
      {
      Direction = ( ( OrderType() * -2 ) + 1 );  //  for a Sell = -1 for a Buy = 1

      if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && 


         ( OrderClosePrice() - OrderOpenPrice() ) * Direction  >=  movestopto*point )           //  if the order is in profit by movestopto points

         {
         deltotal++;
         }
      }
   }   
 
RaptorUK:
   Direction = ( ( OrderType() * -2 ) + 1 );  //  for a Sell = -1 for a Buy = 1

Hide Details when ever possible. From My code
double  Direction(int op_xxx){  return( 1. - 2. * (op_xxx%2) );                }
Note: this works for pending orders as well as opened ones.
 

thank You,

how about this, would it be OK too?

Bid >= OrderOpenPrice() + movestopto*point || Ask <= OrderOpenPrice() - movestopto*point

order1 hits movestopto (fex 3) pending buystop or sellstop is deleted

        bool delpending = false;

        for(int a=OrdersTotal() - 1; a >= 0; a--)
        {
        if(OrderSelect(a,SELECT_BY_POS,MODE_TRADES)==false) break;

        if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
        {
        if (Bid >= OrderOpenPrice() + movestopto*point)
        delpending = true;
        }

        if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
        {
        if (Ask <= OrderOpenPrice() - movestopto*point)
        delpending = true;

        }
        }



        if (delpending==true)
        {

   for(i=OrdersTotal();i>=0;i--)
        {
        OrderSelect(i, SELECT_BY_POS);
        if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber2)
        {
        if(OrderType()==OP_BUYSTOP)   OrderDelete( OrderTicket() );
        if(OrderType()==OP_SELLSTOP)  OrderDelete( OrderTicket() );
        }
        Sleep(1000);
        }

        }
Reason: