I want to close the last order ticket but this isn't working?

 
   int i;                              
   for(i=0; i<OrdersHistoryTotal(); i++)
   {                                    
                                        
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)                         
{
{OrderClose(OrderTicket(),LotSize,Ask,UseSlippage,NULL);}
}
 
  1. Why are you looping by the number of things in History, but looking at orders in trades?
  2. Why are you trying to close all orders, not just the last?
  3. No filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.) Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forum
  4. Define what you mean by last.
  5. Why are you assuming that each ticket has the same size?
  6. Why are you assuming that each ticket is a sell order (close at the Ask)?
  7. Why are you not checking your return codes? What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  8. "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
Reason: