
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
your suggestion is nice but all these functions don't exist, (? half a question)
To the half which is a question, these functions do exist (imo), here for example. Allot of us have posted functions which select the last order in history multiple times. We've also part toke in discussions upon which circumstances such code may break. Now it's up to newer members to search for those posts.
The last order in history is not necessarily the last closed order.
And thats why you ask for the last closed order. With && OrderType()==.
for a state variable, why not sending it by email ?
Cute ;) I see where you're going with this. Don't worry I'm too un-obnoxious to play anonymous smart games. I just try to be humble online, thats all.
Allot of us have posted functions which select the last order in history multiple times.
One which I haven't seen for a while goes as follows:
For the sake of performance, i have the feeling that storing the last closed order in a global variable seems to be quite a decent solution. I guess lucif is get back to hell ? ;-)
( If you want something fun and related to consider... Everyone on this forum - including me - who says that you should close open positions by looping down from OrdersTotal() to 0 is, strictly speaking, wrong. It doesn't work universally. Oanda's proprietary bridge implements a very pedantic interpretation of the FIFO rules and requires that open orders are closed oldest-first. Therefore, looping from OrdersTotal() to zero doesn't work. Instead, you have to do something like building an array of the orders, sorting them by open time to make sure that they're in order, and then closing them using the array; e.g https://www.mql5.com/en/forum/123595 / https://www.mql5.com/en/forum/118657. )
but i'm not sure the algo works if you were short, It does. OP_SELL is a constant which equals 1. OP_BUY is a constant which equals 0.
Check the Documents and the link provided above for a list of Constants and their numeric values.
But for an EA, each time it is executed, the most part of a same history is loaded, parsed and sorted out...
JJC's code is great for someone who wants to be on the safer side. This would be the case if MetaQuotes (or possibly the Broker) ever changes the default sort of the history pool. It provides a good example for sorting arrays. You could save this array to file and create your own backup copy of the trade history.
Currently I believe it goes from first 0 to last OrderHistoryTotal-1 according to OrderCloseTime. So when you do OrderHistoryTotal-1 you get Last-Orders-First. Buy you don't care about 'Balance' statement: OrderType()==6, 'Credit' statement: OrderType()==7 or Canceled Pending Orders. Therefore you tell it to filter those until you find the Last market order which was closed.
Anyways, should your broker start messing with your history or mt4 update and change the sort, you'd wish you'd been using an array and saving to file. But like I said, what you impliment depends on your skills and paranoia. JJC has the skills.
I guess lucif is get back to hell ..... I guess lucif don't care ;)))