Where is my calculation mistake? Backtesting loss does not match calculation.

Poker_player

Active Trader
Jul 26, 2017
23
3
29
24
1605976146157.png
here is USDJPY short open and closed at SL.

1605976193856.png
1605976214977.png
1605976230219.png

So dayly swap eats 6.15 usd. Account is in usd. From jan 22 to feb 6 it has been 17 swaps.
There is no commision.
So my math is 6.15*17+52.5=157.05

but position loss is 175.48.

What am I missing?
I am not sure if swap usd per lot is changing based on usdjpy price. Maybe I should use different, not 6.15 ? How to calculate it if so?
 

Enivid

Administrator
Staff member
Nov 30, 2008
18,535
1,355
144
Odesa
www.earnforex.com
In theory, swaps are modeled in MT4 Strategy Tester using the current rates. In practice, I noticed that they work quite well for USD pairs, but are completely off for non-USD pairs.

In your case, you have an entry price at 109.870 and exit at 109.939. Your rate-based loss is 69 points or 0.79 x 69 x 100 = 5,451 yen. This is 5,451 / 109.939 = 49.58 USD.

175.48 - 49.58 = 125.9 USD, presumably taken by the swaps.

From January 22 till February 6 is 16 days (not sure why you say 17). Let's use nominal swap (in pips) to calculate the swaps: 16 x 8.077 x 0.79 = 102.09. 102.09 x 100 / 109.939 = 92.86 USD.

Even if we adjust the swap days to 18 (because apparently January 22 is Wednesday, which is a triple-swap day), we would arrive only at 104.47 USD.

Obviously, Strategy Tester is using some other value in its calculations.

By the way, you are using a very old version of PSC - you might want to update it.
 

Poker_player

Active Trader
Jul 26, 2017
23
3
29
24
In theory, swaps are modeled in MT4 Strategy Tester using the current rates. In practice, I noticed that they work quite well for USD pairs, but are completely off for non-USD pairs.

In your case, you have an entry price at 109.870 and exit at 109.939. Your rate-based loss is 69 points or 0.79 x 69 x 100 = 5,451 yen. This is 5,451 / 109.939 = 49.58 USD.

175.48 - 49.58 = 125.9 USD, presumably taken by the swaps.

From January 22 till February 6 is 16 days (not sure why you say 17). Let's use nominal swap (in pips) to calculate the swaps: 16 x 8.077 x 0.79 = 102.09. 102.09 x 100 / 109.939 = 92.86 USD.

Even if we adjust the swap days to 18 (because apparently January 22 is Wednesday, which is a triple-swap day), we would arrive only at 104.47 USD.

Obviously, Strategy Tester is using some other value in its calculations.

By the way, you are using a very old version of PSC - you might want to update it.
1606066997543.png

I have counted many times - its 17 swaps. Where is my mistake?

About swaps off - so you mean pair which does not end with USD does incorrect swaps and nobody is fixing this? And everybody are testing with incorrect swaps? Platform is so popular, it is really weird if nobody is fixing this.

So then only way to have correct calculations is for each position to code loss calculation myself?
 

Enivid

Administrator
Staff member
Nov 30, 2008
18,535
1,355
144
Odesa
www.earnforex.com
I have counted many times - its 17 swaps. Where is my mistake?
Your trade is closed at 06:28 on February 6 - that's before the swap is collected (24:00).

If you search MQL5 forums about the issue, you will notice the topics (like this one) discussing the issue - Strategy Tester's swaps are historically incorrect.
 

Poker_player

Active Trader
Jul 26, 2017
23
3
29
24
Your trade is closed at 06:28 on February 6 - that's before the swap is collected (24:00).

If you search MQL5 forums about the issue, you will notice the topics (like this one) discussing the issue - Strategy Tester's swaps are historically incorrect.
Yes, I did not include on feb 6 day ending.
Monday to tuesday - 1
Tuesday to wednesday - 1
wednesday to thursday - 3
next is 6:28
If I would include thursday (6), there would be 1 more. I mean would be thursday to friday swap.

They are not historically accurate, but as in the thread writes:
So your 10 year back test will use the rates of today for the whole period.
But my calculations do not match to loss size by backtest even if I use todays swap for all backtested trades.
 

Enivid

Administrator
Staff member
Nov 30, 2008
18,535
1,355
144
Odesa
www.earnforex.com
Yes, I did not include on feb 6 day ending.
Monday to tuesday - 1
Tuesday to wednesday - 1
wednesday to thursday - 3
next is 6:28
If I would include thursday (6), there would be 1 more. I mean would be thursday to friday swap.
Yes, you are right. I miscalculated the days.

So your 10 year back test will use the rates of today for the whole period.
It looks like this is true only for USD pairs.
 

Enivid

Administrator
Staff member
Nov 30, 2008
18,535
1,355
144
Odesa
www.earnforex.com
They don't match because Strategy Tester doesn't use the latest swap value to calculate swaps during backtests but rather uses some unknown value. You can find that value (and check whether it is fixed) by running some backtests to take several experimental trades that last only one day (and incur only one swap payment) on several different days.
 
  • 👍
Reactions: Poker_player

Poker_player

Active Trader
Jul 26, 2017
23
3
29
24
They don't match because Strategy Tester doesn't use the latest swap value to calculate swaps during backtests but rather uses some unknown value. You can find that value (and check whether it is fixed) by running some backtests to take several experimental trades that last only one day (and incur only one swap payment) on several different days.
Good idea. I just dont get why it is made like this :D what are they smoking. Why I cannot find in documentation abou this :)
 

Poker_player

Active Trader
Jul 26, 2017
23
3
29
24
Have printed swap each day:

2020.11.30 20:55:10.728 2020.02.06 00:00:00 adx USDJPY,H1: swap: -98.7114401
2020.11.30 20:55:10.728 2020.02.05 00:00:00 adx USDJPY,H1: swap: -81.29177420000001
2020.11.30 20:55:10.727 2020.02.04 00:00:00 adx USDJPY,H1: swap: -75.48521890000001
2020.11.30 20:55:10.727 2020.02.03 00:00:00 adx USDJPY,H1: swap: -69.67866360000001
2020.11.30 20:55:10.727 2020.01.31 00:00:00 adx USDJPY,H1: swap: -63.87210830000001
2020.11.30 20:55:10.721 2020.01.30 00:00:00 adx USDJPY,H1: swap: -58.06555300000001
2020.11.30 20:55:10.721 2020.01.29 00:00:00 adx USDJPY,H1: swap: -40.6458871
2020.11.30 20:55:10.721 2020.01.28 00:00:00 adx USDJPY,H1: swap: -34.8393318
2020.11.30 20:55:10.720 2020.01.27 00:00:00 adx USDJPY,H1: swap: -29.0327765
2020.11.30 20:55:10.720 2020.01.24 00:00:00 adx USDJPY,H1: swap: -23.2262212
2020.11.30 20:55:10.720 2020.01.23 00:00:00 adx USDJPY,H1: swap: -17.41966590000001
2020.11.30 20:55:10.719 2020.01.22 00:00:00 adx USDJPY,H1: commission -3.16
2020.11.30 20:55:10.719 2020.01.22 00:00:00 adx USDJPY,H1: open #1 sell 0.79 USDJPY at 109.841 sl: 1000.000 ok

and as we can see difference is about 5.8 or 3x 5.8 each day.

So swap is constant value. But even smaller than position size calculator showing. Maybe because old version position size calculator showing wrong value.
So no idea. This is such a mystery. And even in mql forum nobody explains.
 
Last edited:
  • 👍
Reactions: Enivid

Enivid

Administrator
Staff member
Nov 30, 2008
18,535
1,355
144
Odesa
www.earnforex.com
You can check whether the PSC shows the correct swap value by opening a trade on demo and holding it for a night.

The swap value for USD/JPY (if it is of type "Pips") should fluctuate from day to day even without changes in the interest rates difference just because its USD value depends on the USD/JPY rate at application time.