Basic question about order execution

 

I'm sorry if I've missed something really obvious ...

Is there an order state I've missed which indicates an order has changed from pending to active? I've been doing this by checking if highs and lows have equaled or exceeded the OrderOpenPrice(), but it seems there ought to be an easier way. Is there some sort of order active flag I've missed?

Thanks.

 

Select orders in the normal way and then filter with order type to get currently active orders

https://docs.mql4.com/trading/OrderType

HTH

V

 
Viffer:

Select orders in the normal way and then filter with order type to get currently active orders

https://docs.mql4.com/trading/OrderType

HTH

V


Thanks for the reply. I'm not quite getting OrderType ...

1) I see code like "if(OrderType()==OP_BUY)" so I think it's a string. But it returns integers.

2) I can't make the numbers line up with the type list in the documentation.

Opening a SELLSTOP returns 0.

When the price is hit it returns 1.

Sending a BUYSTOP returns 4.

 

The constants are special defined values... Ordertype returns an integer


https://docs.mql4.com/constants/trading


if(OrderType()==0) would be just as effective.

V

 

"(OrderType()==OP_BUY)" OP_BUY is a string which corresponds to integers. The link provided by Viffer may gave the full list of what Strings corresponds to which number if you look around. If you want to know if your order has gone for pending to active then like Viffer said you do a search for either active or pending orders.

 

If however you're looking for something to pop-up and say pending order is now active then you'll need to use some more creativity. I don't have any thing for that off the top of my head at the moment. 

 

Sorry, I may have read this too fast.

"Opening a SELLSTOP returns 0." - Not sure what you mean but if you select the order it should have an order type of 5 and then when the price is hit and it becomes an active sell, order type would change to 1. Is this not the case?

 
ubzen:

If however you're looking for something to pop-up and say pending order is now active then you'll need to use some more creativity. I don't have any thing for that off the top of my head at the moment.

Just for fun... I haven't tested it but I think it would get the job done.

   static int lastcount;
   int   count,i,type,magic;

   for(int i=OrdersTotal()-1; i>=0; i--)                                                
      {
      if (OrderSelect(i,SELECT_BY_POS)==true)                           
         {                                                                  
         type=OrderType();                                              
         
         if (OrderSymbol()!=Symbol()||type>1 || OrderMagicNumber()!=magic)
            {
            continue;
            }                           
         count++;
         }
       }
    if (count>lastcount)  
       {
       Alert("Oi UBZEN, A pending order is now active :)");
       }
    
    lastcount=count; 
EDIT: Missed a couple of ;'s
Reason: