Select last open order

 

Hi,

I'm writing a code in which I open an order manually when I wanted, and the expert checks if there is an open order or not. if there is an open order it has to take control of the closing and some other stuff.

the problem is, when i open an order manually, how can I select the open order to continue using its price and other properties?


thanks in advance

Hadi

 
if(OrdersTotal()!=0)
           {
           OrderSelect(0, SELECT_BY_POS);
           TicketDate=OrderOpenTime();
           StartTime=TicketDate; 
           TicketNumber=OrderTicket(); 
           TicketType=OrderType(); //OP_BUY OP_SELL
           if (TicketType == OP_BUY)
              {TicketTypeStr = "Buy";}
           else if (TicketType == OP_SELL)
              {TicketTypeStr = "Sell";}   
           
            Comment ("Found Existing Open Order ",TicketTypeStr,"#",TicketNumber," ",
            TimeToStr(TicketDate,TIME_DATE)," , ",TimeToStr(TicketDate,TIME_MINUTES)); 
                       
            //your additional code here         
           }
           else
           {
               Comment ("No Open Orders");
           }
 

Hadi, manual opened orders have Magic number 0. This may help you.



Last opened order can be detected by its OrderOpenTime()

 

Thnaks Meikel and fx1.net

you solved my problem.


regards,


Hadi

Reason: