Hi
After i use “PositionClose()” and my open position get closed, I want to know ticket of the last order and use “GetLastOrderTicket()” Function as below:
but the ticket returnd is for The last one left. How can i fix it?
ulong GetLastOrderTicket()
{
//--- request history for the last 10 days
if(!GetTradeHistory(10))
{
//--- notify on unsuccessful call and return -1
Print(__FUNCTION__," HistorySelect() returned false");
return -1;
}
//---
ulong first_order,last_order,orders=HistoryOrdersTotal();
//--- work with orders if there are any
if(orders>0)
{
// Print("Orders = ",orders);
first_order=HistoryOrderGetTicket(0);
// PrintFormat("first_order = %d",first_order);
if(orders>1)
{
last_order=HistoryOrderGetTicket((int)orders-1);
Print("GetLastOrderTicket 1 Num orders:",orders," first_order:",first_order," last_order:",last_order);
return last_order;
}
return first_order;
}
//--- no order found, return -1
return -1;
}