Hi @fxDreema
i wonder about the "for each Closed Trade" function..
I use it to analyze the last n trades profit using the method "Newest to Oldest"
looking at the mq4 code, here mine two questions:
-
i thought the function returns the last n trades ordered from Close Time, is that right?
Or it returns the last n trades opened and already closed? -
probably i'm wrong but it looks like the "For each Trade" model does not sort by ticket or date
and looking around on forums i found this two statements:
From MQL4 Guide link text
"Consecutive selection of orders using the SELECT_BY_POS parameter returns information in the sequence in which it was received from the trading server. Sorting of the resulting list of orders cannot be guaranteed."
and from link text
"I found that in both 'trade pool' and 'history pool', the list is sorted by time the trade is opened."
"When back testing this seems to work as you might expect with orders entering the list sequentially. When done in live accounts you are better off considering the ordering as random and sorting it yourself."
"By the way, the OrdersHistory also contains balance transfers, identifiable as OrderSymbol()==""
If you have 5 or 6 orders in your history you may be lulled in a false sense of security and think you have the pattern figured out. I just checked it this evening to make sure and of 150 trades in the history there are not just a few out of date order, but lots. The first errors didn't appear until 30 items into the list."
"There is no explicit documentation of the sorting order of this list, so better considering it as random sorted, as Dabbler suggested. It can depend on brokers also.
Perhaps there is a more experienced programmer here, who can point the documentation of this. But, if not, when the sequence of list is critical, you should build a custom array of it, then sort yourself."
With all that said, how can i reliable check the last n trades closed (ordered by oldest closing time)?
Thank you
Dave