Download MetaTrader 5

Retrieving Last closed Order's Ticket - page 2

To add comments, please log in or register
Publish your trading signal. Gain access to millions of traders!
James Hodges
James Hodges 2014.03.22 21:53  
but in the strategy tester it's accurate ;-)

I am using that code on live accounts in an EA and can't get it to give me a wrong answer. If they have a way to make the highest indexed trade not be the most recent one though i'd like to know about it... it could cause some problems....
Keith Watford
Keith Watford 2014.03.22 22:54  

I'm here to learn. what part of this is not always true. I have been unable to get any other order than the last closed order to show using this method no matter how i arrange them in my accounts history ledger. I always assumed that the numbering of the closed orders on the server was done by OrderCloseTime . Enlighten me please.

I just ran your code

int i =OrdersHistoryTotal()-1;
double closingPrice =OrderClosePrice();


05:48:42 Script aaa AUDUSD,H1: loaded successfully

05:48:42 aaa AUDUSD,H1: initialized

05:48:42 aaa AUDUSD,H1: 102.287

05:48:42 aaa AUDUSD,H1: uninit reason 4

05:48:42 Script aaa AUDUSD,H1: removed

As you can see, it was not the last closed trade


Alain Verleyen
Alain Verleyen 2014.03.22 23:03  

As WHRoeder has not posted it yet, I do it Could EA Really Live By Order_History Alone? - MQL4 forum.

James Hodges
James Hodges 2014.03.23 04:41  

Hey thanks guys! This is good info indeed! I just ran that code on several live accounts and it works on most of them just fine. However on one broker it was not working properly. After further investigation it looks like that particular broker's indexing of the orders in history is done by each orders OPENING time instead of it's CLOSING time. Glad you guys brought this to may attention.. many thanks... PipPip ...Jimdandy

p.s ..was wondering why you were getting an unitialization reason of 4.. I always get 0 ..

Keith Watford
Keith Watford 2014.03.23 06:22  

p.s ..was wondering why you were getting an unitialization reason of 4.. I always get 0 .

I have no idea. I certainly didn't close the chart.

Arav007 2014.03.23 08:56  
If you wanted to write it to get the ticket number of the trade with the highest closing time you might do it like this.....
I wrote that kind of quick so there may be some errors in it for you to work out. But i think you get the idea... PipPip..Jimdandy

Thanks once again for your input. The way you defined everything is quite easy for me to understand.

Here I am getting something strange though. I am not understanding how it's counting orders and displaying the Tickets.

Actually my plan is to compare the 'BuyOrder_3/SellOrder_3' of the '3 Simultaneous' orders this EA is opening.

The EA opens a New set of '3 Simultaneous' orders when the Last Opened order i.e. BuyOrder_3/SellOrder_3 gets closed.

Now I am trying that the EA will open '3 Simultaneous' order just once when it gets say Buy signal. Then if all the 3 orders

get closed either by SL/TP and the Buy signal is still 'Valid' it will Open only 'One' order instead of 'Three' orders.

That is why I'm trying to access the 'History' and check if that BuyOrder_3/SellOrder_3 got Closed so that I can set a single odersend function there.


To add comments, please log in or register