Backtesting: same operations, different outputs

 
Hello everyone.
I have an Expert Advisor I want to backtest on metatrader4.

Unfortunately I have come to what I consider a real big issue. I noticed that when I test some trades starting soon before their moment, I have some profit results, but when the same situation  occurs when I'm in the middle of a test started 9 years before, I have different profit and equity values. It's important for you to know that: 1) the Advisor has no memory of the past, except for a couple of global variables but only for exposition purposes in order to remember and show the highest balance reached, but this don't affects the decisions, so it's supposed to behave exactly at the same way, both it is its first operation or its thousandth, 2) I am on EURUSD (micro account), both tests on same daily chart, and spread is fixed at 18 points, 3) after cleaning up chart history and importing brand new bars from a different source I had the same bad behavior, with small variations due to slighty different OpenCloseHighLow values, 3) open/close prices and times and lots are exactly the same in both tests, but profit and equity values differ!

Let me show you:



In this first image you can see a situation with four buys and four losses. Under a certain price I close them all, I register their profit and print out on that red vertical text. -6.94€ and fine. I also higlighted you two peakes the market reached: in the first peak, the lower one, my equity reached +7.26€ and in the second, higher, the equity grows to +9.80€, an higher value as I would expect. I precise that when I say "equity", I mean
double equity = AccountEquity() - AccountBalance();
if (maxDailyEquity < equity) {maxDailyEquity = equity;}

because I am interested in the difference. maxDailyEquity is where the peak values I told you before are taken: it is set at -100000 every new bar and then it updates every tick with the highest equity during the daily bar.

Now you see this second picture, with the same Expert tested since 2005, 9 years before.


This is the exact same moment, the same situation. The four buys showed are the same as above: same open/close price, same open/close time, same lots, as I would expect because, as I said before, the Advisor cleans itself and restart each time. The problem is, as you can see, that the profits are way different and the loss is expanded of a factor of almost two. The equity values differ too. Of course AccountBalance() and AccountEquity() have changed in nine years of testing, but the difference of them, having the same open trades, should not, and still I have this strange behavior: at first peak, the lower, my equity gets to 7.12€; some days after, on the second peak, on an higher price, my equity is only 6.10€ with the very same trades open as before. Of course with more profit points I would expect some more profit in my account currency (euro).

This is really struggling me. In some other cases coming after this, my Expert would be supposed to close trades when a certain equity is reached: if I test them with a short time test the equity is reached; if I test them with a 9/10 years test, the equity has lower values (as the peaks showed above), the value is not reached and I collect a loss. Of course I am not here to discuss the validity of my system and decide whether I deserved those losses, or not. But in order for me to know it and do something to improve it, you understand I need a reliable testing environment with repeatable tests.

I tried and look for some similar topics but I wasn't able to find anyone. Am I missing something? My only thought by now is about some kind of precision and/or overflow of double variables, accumulated for some reasons after many trade operations tested.

I hope in some hints coming from this community of qualified programmers and I am fully available for further details.

Thanks in advance.

Alessandro
 
Update:
I tried the same on a new machine with fresh imported bars and it happened that the short time and the long time tests both gave the same results. 
I was very happy until I noticed that I forgot to change a parameter: the starting balance. I kept the default one of 10000 US$ and all the calculations went for good. 
I changed it to 100000 € as I used to and the same issue represented itself again.
Here two pictures attached of the two good tests: perfectly equal both stsrting in 2005 or 2014.
Maybe I found a way to fix the output, but the question is still valid. 
Thanks to anyone will partecipate. 
Files:
2.jpg  373 kb
4.jpg  370 kb
 
Update: tested with a starting balance of 10000 € and the issue represents. So I suppose it's something about the account currency, and not the high value of the starting balance.
I noticed one more thing: if you look the second picture of my first post, I told you there are buy trades which lose more in the long time test. Now I noticed that the sell trades which are closed before these 4 buys, they lose 0,77€ in that test.
Yet they lose more in the brief test, the one in which buys lose less! I attach one more pic.

So maybe it's something about a simulation of the swap, could it be? But then why being different in the long run test, and in the short time one? 

Files:
05.png  140 kb
Reason: