Strategy tester profit calculation - Is it a bug?

 

Hi,

I recently downloaded MT4 and started developing my own scripts.

I ran the Strategy tester on some simple expert adviser.
Here are some lines from the report produced by MT4: (I removed some of the non relevant information)

Line#
Date & TimeID
Lots
Rate Profit
1
buy2005.01.03 04:081
0.101.34820
2
sell2005.01.03 08:332
0.101.34860
3
buy2005.01.03 14:483
0.101.34700
4sell2005.01.11 01:3040.10 1.3125
0
...





12close2005.02.02 03:0810.10
1.3072
-410.00
14close 2005.02.03 14:00
20.10
1.2992
494.00
16close2005.02.04 14:30
30.101.3042
-428.00
18
close2005.02.04 14:504
0.101.2939 186.00


I was wondering how did MT4 calculate the profit. After a short time I found the answer.


The formula MT4 uses for calculating the profit is: (sell - buy)*investment // where investment is lots*lotSize

For example:
ID
Buy rate
Sell rate
lots*lotSize
Formula
Result
1
1.34821.307210000
(1.3072-1.3482)*10000-410
21.2992 1.3486
10000(1.3486-1.2992)*10000 494
3
1.3470 1.304210000
(1.3042-1.3470)*10000-428


As you can see with this formula I got the same results as MT4. This is the formula MT4 uses.

Now, lets try this formula on some simple examples:
Case
Type
Open
Close
Formula
Result
1
long
1
2
(2-1)*10000
10000
2
long
2
1
(1-2)*10000 -10000
3
short
2
1
(2-1)*1000010000
4
short
1
2
(1-2)*10000-10000

It looks to me that these results are wrong.
Take cases 2 and 4 for example:
If you buy something at price 2 and sell the same thing for price 1
you should lose half of your investment not all of it. In this case your profit should be -5000 not -10000.

If I understand correctly, the correct formula for calculating the profit is: ((investment/buy)*sell) - investment
With this formula for the same cases we get:
Case
Type
Open
Close
Formula
Result
1
long
1
2
(10000/1)*2 - 1000010000
2
long
2
1
(10000/2)*1 - 10000-5000
3
short
2
1
(10000/1)*2 - 1000010000
4
short
1
2
(10000/2)*1 - 10000-5000

As for my understanding these are the correct results and not the results we got from formula used by MT4.
If I use this formula on the lines from the MT4 report I get completely different results:
ID
Buy rate
Sell rate
lots*lotSizeFormula
Result
1
1.34821.307210000
(10000/1.3482)*1.3072 - 10000-304.11
2
1.2992 1.348610000(10000/1.2992)*1.3486 - 10000 380.23
3
1.34701.304210000(10000/1.3470)*1.3042 - 10000 -317.74

Is this a bug in MT4????
Am I missing something?

EP.
 
See article Forex Trading ABC