Serious bug in the OrderCalcProfit() function - page 5

 
Alain Verleyen #:

Not at all.

I did nothing, it's all "normal" trades open and close in a standard way, CLOSE_BY was not used.

If it was not a close-by, then you should contact your broker. Seriously, he is not honest..
 

Here the most significant trades (difference between profit calculated with ask or bid greater than 0.02) :

[2021.09.29 22:00:00.873]:  BUY   [P/L {Bid}=  37.64       {Ask}=  37.59 MATCH {MT5}=  37.59] GBPNZD v:0.08 o:1.94514 c:1.95308 [EURNZD: I {Bid}=1.68765 {Ask}=1.68985 at {2021.09.29 22:00:00.224}
[2022.04.25 07:14:39.357]:  BUY   [P/L {Bid}=-227.12       {Ask}=-227.08 MATCH {MT5}=-227.08] GBPCAD v:0.08 o:1.66583 c:1.62700 [EURCAD: I {Bid}=1.36775 {Ask}=1.36796 at {2022.04.25 07:14:39.268}
[2022.04.27 00:00:01.185]:  BUY   [P/L {Bid}=-183.75       {Ask}=-183.72 MATCH {MT5}=-183.72] GBPCAD v:0.08 o:1.64238 c:1.61106 [EURCAD: I {Bid}=1.36360 {Ask}=1.36381 at {2022.04.27 00:00:00.275}
[2022.07.27 00:00:00.558]: SELL   [P/L {Bid}=-100.62 MATCH {Ask}=-100.59       {MT5}=-100.62] AUDNZD v:0.11 o:1.09879 c:1.11364 [EURNZD: I {Bid}=1.62347 {Ask}=1.62390 at {2022.07.27 00:00:00.079}
[2022.08.28 23:05:00.769]:  BUY   [P/L {Bid}= -97.41       {Ask}= -97.38 MATCH {MT5}= -97.38] GBPAUD v:0.07 o:1.72421 c:1.70407 [EURAUD: I {Bid}=1.44725 {Ask}=1.44774 at {2022.08.28 23:05:00.531}
[2022.08.28 23:05:00.871]:  BUY   [P/L {Bid}=-227.67       {Ask}=-227.59 MATCH {MT5}=-227.59] GBPAUD v:0.07 o:1.75114 c:1.70407 [EURAUD: I {Bid}=1.44725 {Ask}=1.44774 at {2022.08.28 23:05:00.531}
[2022.09.25 23:11:01.796]: SELL ♥ [P/L {Bid}=-142.50       {Ask}=-142.38 MATCH {MT5}=-142.38] EURGBP v:0.04 o:0.86483 c:0.89675 [EURGBP: I {Bid}=0.89598 {Ask}=0.89675 at {2022.09.25 23:11:01.616}
[2022.09.26 01:58:57.862]:  BUY   [P/L {Bid}=-336.36       {Ask}=-336.32 MATCH {MT5}=-336.32] GBPUSD v:0.03 o:1.16344 c:1.05581 [EURUSD: I {Bid}=0.95996 {Ask}=0.96008 at {2022.09.26 01:58:57.803}
[2022.09.27 00:00:01.199]:  BUY   [P/L {Bid}=-254.30       {Ask}=-254.26 MATCH {MT5}=-254.26] GBPAUD v:0.07 o:1.71044 c:1.65639 [EURAUD: I {Bid}=1.48783 {Ask}=1.48807 at {2022.09.27 00:00:00.255}

EUR Account. Checked: 9, No match 8 (Logic:Direct: BUY:Ask SELL:Bid - Indirect: BUY:1/Bid SELL:1/Ask)
v=volume, o=open price, c=close price, I is for indirect conversion (1/Bid or 1/Ask).

Only 1 is following "your" logic. Why only one ?

I have no explanation, it is as it is. It's mainly losing trades, but that's because the P/L is greater when in loss

If I checked more trade (diff 0.01), I got :

EUR Account. Checked: 33, No match 27 (Logic:Direct: BUY:Ask SELL:Bid - Indirect: BUY:1/Bid SELL:1/Ask)

Doesn't make sense to me.

I will check more accounts, and also check it live.

 
Alain Verleyen #:

Here the most significant trades (difference between profit calculated with ask or bid greater than 0.02) :

Only 1 is following "your" logic. Why only one ?

I have no explanation, it is as it is. It's mainly losing trades, but that's because the P/L is greater when in loss

If I checked more trade (diff 0.01), I got :

Doesn't make sense to me.

I will check more accounts, and also check it live.

I only use prop firms with USD now but when I first started I had to decide if my CAD deposits would be made in an account with CAD as the base currency or if I would create an account with USD as the base currency, in which case the broker would convert the deposited funds and charge a conversion fee. I'm not sure if my instincts were correct but since most pairs I trade are denominated in USD, I always thought it would be safer to use USD as my account's base currency because I feared that otherwise I would end up being screwed with a conversion fee (spread) everytime I close a trade. Maybe that's what's happening to you. Not sure though. My guess is it might be different depending on how your broker handles each account base currency, but since I now only use accounts with USD as the base currency, I don't worry about this anymore.

for example, I found this:

  • For currency trades executed under the auto currency conversion service (for customers who opened their account through the ****** App), ***** will typically add or subtract (at its discretion) 0.03% to the exchange rate that would otherwise apply. Please note that ****** does not separately charge a commission on these auto-conversion trades.
I don't know if this applies to FX trades, but like I said, I keep accounts in USD so that I don't have to worry about an extra conversion fee hidden in the backend of the trade, just in case.
 
Alain Verleyen #:

Only 1 is following "your" logic. Why only one ?

I have no explanation, it is as it is. 

What I can see is that it is the only one with the account currency (EUR).

This broker shorts the conversion pair for the long trades, and longs it for the short ones.
 

found something else (for the same broker):

"********* will automatically convert currencies when trading non-GBP denominated securities. To do this, ************* will engage in “spot” currency transactions on your behalf in order to settle your buy orders or convert the proceeds of a sell order."

This is why I wouldn't be surprised if trade profit conversion to account currency could be done differently based on what broker you use and what's your account currency.

 
amrali #:

What I can see is that it is the only one with the account currency (EUR).

This broker shorts the conversion pair for the long trades, and longs it for the short ones.
You are right, there is something there !
 

My final conclusion:

Profit calculations using OrderCalcProfit() and tick values are matching, but they do not match their actual values. The actual profits (either floating or closed) that we get on the platform can not be explained by any means and do not follow any logic. There is something strange happening on the server side. Only the developers of the platform have the proper explanation. 

@Alain Verleyen I think your research into profit calculation of the closed trades will yield nothing at the end, like mine on live positions.

 
amrali #:

My final conclusion:

Profit calculations using OrderCalcProfit() and tick values are matching, but they do not match their actual values. The actual profits (either floating or closed) that we get on the platform can not be explained by any means and do not follow any logic. There is something strange happening on the server side. Only the developers of the platform have the proper explanation. 

@Alain Verleyen I think your research into profit calculation of the closed trades will yield nothing at the end, like mine on live positions.

When you say the actual profits you get on the platform aren't matching, what if you use my script (see below link)? What I'm wondering is if the profits you see on your closed position (in your history) doesn't match the calculations, do the calculations from my script match the profits you see if you hover over your position's Stop Loss on the chart while the position is still open? Does the discrepancy affect these profit calculations while the position is open or does it only affect the true profits you get after the position is closed?

https://www.mql5.com/en/forum/441959/page6#comment_45209672

SYMBOL_TRADE_TICK_VALUE_LOSS vs SYMBOL_TRADE_TICK_VALUE_PROFIT
SYMBOL_TRADE_TICK_VALUE_LOSS vs SYMBOL_TRADE_TICK_VALUE_PROFIT
  • 2023.02.24
  • www.mql5.com
*edit: when I posted the thread, I was confused about the correct way to calculate position size based on entry price and stop loss price, so don't...
 

Please refer to post #35 for the analysis I did on live positions. https://www.mql5.com/en/forum/439319/page4#comment_45156522

Live (floating) profits calculations using OrderCalcProfit() and tick values are matching exactly and they follow the rules for the profit -> account currency conversion rates.

However, the actual profit reported by the terminal (POSITION_PROFIT field) cannot be re-calculated with any equation.

Forum on trading, automated trading systems and testing trading strategies

Serious bug in the OrderCalcProfit() function

amrali, 2023.02.21 23:35

Here is the result from the EUR account:

Here is the result from the USD account:

As can be seen  POSITION_PROFIT is sometimes (but not always) equal to profit calculation using  OrderCalcProfit(). The reason for this may be a timing (sync) issue between the ticks on the server used to calculate the POSITION_PROFIT  field and the later ticks reaching the terminal. So, my conclusion is that the value of the POSITION_PROFIT field is calculated on the server, independent of the quote data arriving to the terminal in that exact moment.

Serious bug in the OrderCalcProfit() function - How to check live and record profits in the Strategy Tester; There is a big misunderstanding between us as several issues between
Serious bug in the OrderCalcProfit() function - How to check live and record profits in the Strategy Tester; There is a big misunderstanding between us as several issues between
  • 2023.02.19
  • www.mql5.com
I think there is big misunderstanding between us as several issues were discussed and mixed. I ran the test on two different terminal, one with an account currency = eur, the other's account currency is usd
 
amrali #:

Please refer to post #35 for the analysis I did on live positions. https://www.mql5.com/en/forum/439319/page4#comment_45156522

Live (floating) profits calculations using OrderCalcProfit() and tick values are matching exactly and they follow the rules for the profit -> account currency conversion rates.

However, the actual profit reported by the terminal (POSITION_PROFIT field) cannot be re-calculated with any equation.

Ok, I'll review those in case I can figure out if we're missing something.

By the way there was something missing in my code and the example you provided to make sure the conversion logic is not applied to CFD pairs so I posted the update in the other thread if you want to check it out.

Reason: