MQH file with a function that process the last N trades closed profit in money (ordered by biggest close time)

MQL4 Integration Beratung

Auftrag beendet

Ausführungszeit 47 Minuten

Spezifikation

 i need a simple MQH file with just a function that process the last N trades closed profit in money (but ordered by biggest close time) 

In “pseudo” code it would be something like this

Int N,X, Var3
double Var1, Var2


first loop
for the last N closed trade (ordered by biggest close time) 
Var1 = Var1 + Trade profit
loop end

second loop
for the last N closed trade (ordered by biggest close time) skipping the first X trades (so if x=2 the loop skip the last two closed trade) 
Var2 = Var2 + Trade profit
loop end


If Var1>Var2 then Var3=0
Else If Var1<Var2 Var3=1

Else If Var1=Var2 Var3=2


------------
in other words

if in my history there are 10 trades what i need is
with N=5, x=2

loop 1 the sum of profit of the trade 10+9+8+7+6
loop 2 the sum of profit 8+7+6+5+4

the number of trade is ordered from close time not from opening or ticket
-----------------


then i need you to explain me how to retrive Var3 value in my EA after the 

#include <File name>


Please note

1) that the trade history probably has to be ordered by biggest Close Time because i found 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."


Bewerbungen

1
Entwickler 1
Bewertung
(213)
Projekte
246
45%
Schlichtung
42
10% / 57%
Frist nicht eingehalten
5
2%
Frei
2
Entwickler 2
Bewertung
(51)
Projekte
66
30%
Schlichtung
2
0% / 0%
Frist nicht eingehalten
0
Frei
3
Entwickler 3
Bewertung
(620)
Projekte
680
57%
Schlichtung
25
16% / 60%
Frist nicht eingehalten
228
34%
Frei
4
Entwickler 4
Bewertung
(94)
Projekte
148
59%
Schlichtung
16
38% / 13%
Frist nicht eingehalten
25
17%
Frei
Veröffentlicht: 1 Beispiel

Projektdetails

Budget
30+ USD