SYMBOL_TRADE_TICK_VALUE_LOSS vs SYMBOL_TRADE_TICK_VALUE_PROFIT - page 4

 
Alain Verleyen #:

I will check your results and investigate further on my side.

Will post my feedback...not sure when though.

amrali #:

I am also having no explanation for your trade @Alain Verleyen. I told you before it is contradictory to my previous tests.

I don't know if this is how it works, but this honestly blows my mind. As soon as you imagine that it's your broker buying or selling from you instead of you buying or selling from them in order to convert profits/losses, you now need to use the ask instead of the bid and vice versa. If you lose EUR, it means you owed them AUD so they bought EUR from you to cover your AUD debt. If you gain EUR, it means they sold you EUR to cover their AUD debt.

Is this crazy? I think it's worth thinking about...

But I also ran some tests with my terminal and so far with a BUY/LONG position on EURGBP and an account in USD, the GBPUSD conversion seems to be with the ASK no matter if it's a loss or a profit. But I'm also doing my best to avoid slippage and can't guarantee it so I can't be 100% this is not a coincidence.

This is so confusing lol.

 
amrali #:

Yes I came to the same conclusion looking at your data, it seems like there's a bit of slippage in the prices you gather with your script. So I try to take some of the trades to see if the true profit was obtained by converting with the ask or the bid and I can't tell which one was used because the numbers don't match any of them. In this case can we honestly draw any conclusions from this data? How do you know that the ones that match, if any, don't just match out of a coincidence?

 

I just ran some tests, the way I did it was with placing orders on the chart with a SL and TP 1000 points away from the entry and I tried to use perfect timing to capture a screenshot of the market watch values at the exact same time I was hovering over the TP or SL to get the loss/profit amounts, while trying to make sure the bid/ask on the conversion pair wasn't changing before I got to take the screenshot. Then I entered all the values in excel and compared the profit/loss amount I got when hovering over the SL and TP to the value I manually calculated using both the bid and the ask of the conversion pair.

The results were still confusing but consistent. 

1. With profits or losses on a EURGBP long trade, the GBPUSD ASK was used to convert the profits and the losses.

2. WIth profits or losses on a EURCAD long trade, the USDCAD BID was used to convert the profits and the losses.

So for a BUY order (long position), the conversion was always with the ASK if the account currency was the quote currency in the conversion pair (GBPUSD), no matter if a profit or a loss.

And if the account currency was the base currency in the conversion pair (USDCAD), the conversion was always done with the BID.

This only tells me that it doesn't matter if it's a PROFIT or a LOSS (at least for forex pairs... I read somewhere that it *might* be different for stock indices) when dealing with a trade on a pair that doesn't include the account's currency.

And it also tells me that on these pairs, what matters is only if the account currency is the quote or the base currency in the conversion pair.

Now I want to test this on a SELL order (short position), but I need a break to let my eyes rest so I might only do it tomorow. I really don't know if I should expect the results to be the opposite or the same, I'll have to see.

I at least feel like the results are consistent so I might keep trying to understand what's going on by running these kinds of tests.

If we look at Alain's example, he had a BUY order on GBPAUD and his account was in EUR, so converted using EURAUD, where his account's currency is the base currency in the conversion pair. This would mean, according to my tests, that the conversion should have been done with the BID, but his conversion was done with the ASK. So I can't tell you what this means, either there was a sync issue in his test and it's hard to tell for sure because he's looking at only 0.07 lots or maybe each broker might have their own method of conversion (I hope this is not what's going on).

 
I found something 100x more detailed than anything I ever read before:


https://www.mql5.com/en/articles/10211

See section:

Most accurate method for calculating the profit and loss of orders


There is so much detail I can't understand it right now, too tired, too much to read. But from the overview I did I think it explains exactly what is happening at the conversion stage and if the bid or the ask should be used.

Market math: profit, loss and costs
Market math: profit, loss and costs
  • www.mql5.com
In this article, I will show you how to calculate the total profit or loss of any trade, including commission and swap. I will provide the most accurate mathematical model and use it to write the code and compare it with the standard. Besides, I will also try to get on the inside of the main MQL5 function to calculate profit and get to the bottom of all the necessary values from the specification.
 

All my tests point to this system:


If account currency = ACC


PAIRS EXPRESSED AS XXXACC:

#1 ACC Profits & losses on BUY/SELL positions for XXXACC stay in ACC, no conversion needed


CONVERSION PAIRS EXPRESSED AS ACCXXX:

#2 XXX Profits & losses on BUY positions for ACCXXX are converted by multiplying the XXX profits by 1 / ACCXXX POSITION_CLOSE_PRICE(BID)

#3 XXX Profits & losses on SELL positions for ACCXXX are converted by multiplying the XXX profits by 1 / ACCXXX POSITION_CLOSE_PRICE(ASK)

#4 XXX Profits & losses on BUY positions for ZZZXXX are treated the same way as profilts and losses from number #2.

#5 XXX Profits & losses on SELL positions for ZZZXXX are treated the same way as profilts and losses from number #3.


INVERTED CONVERSION PAIRS - if the conversion pair is expressed as XXXACC - reverse the conversion logic:

#6 XXX Profits & losses on BUY positions for ZZZXXX are converted by multiplying the XXX profits by XXXACC's ASK INSTEAD OF XXXACC's BID

#7 XXX Profits & losses on SELL positions for ZZZXXX are converted by multiplying the XXX profits by XXXACC's BID INSTEAD  OF XXXACC's ASK


It seems like the tests I run follow these rules consistently accross all symbols in my terminal. So I think it's worth asking if any tests that contradict this can be trusted and/or replicated. If anyone finds an example that doesn't follow this rule, the first thing that I would do is try to replicate the test results to make sure they are reliable before using them to alter this sytem. Perhaps every exception we found so far were coincidences caused by syncronization issues and may not be replicable under a better controlled test environment.

 
Jeepack #:

But I also ran some tests with my terminal and so far with a BUY/LONG position on EURGBP and an account in USD, the GBPUSD conversion seems to be with the ASK no matter if it's a loss or a profit. But I'm also doing my best to avoid slippage and can't guarantee it so I can't be 100% this is not a coincidence.

This is so confusing lol.

That's what I said before:

SYMBOL_TRADE_TICK_VALUE_PROFIT  is used only to calculate profit of SELL orders.

SYMBOL_TRADE_TICK_VALUE_LOSS  is used only to calculate profit of BUY orders.


  1. SYMBOL_TRADE_TICK_VALUE_LOSS  is used to calculate profit of BUY orders.
  2. SYMBOL_TRADE_TICK_VALUE_PROFIT  is used to calculate profit of SELL orders.
  3. No correlation between the TICK_VALUE_xxxx names (PROFIT/LOSS) and the price type (BID/ASK) of profit/account currency conversion rate.
  4. The price type (BID/ASK) of the profit/account conversion pair depends to two things: (a) the type of the order (b) position of account currency in the pair (first or second).
  5. It was better if the names were SYMBOL_TRADE_TICK_VALUE_BUY (for SYMBOL_TRADE_TICK_VALUE_LOSS) and SYMBOL_TRADE_TICK_VALUE_SELL (for SYMBOL_TRADE_TICK_VALUE_PROFIT)

Edit:

Alain, was wrong from the start of the discussion.

Edit2:

It is not that the brokers exchanges (buy / sell) your profit or loss into account currency.

It is a simple rule: The trade type on the conversion pair is the same as that of the traded pair.

 

Forum on trading, automated trading systems and testing trading strategies

SYMBOL_TRADE_TICK_VALUE_LOSS vs SYMBOL_TRADE_TICK_VALUE_PROFIT

Jeepack, 2023.02.22 06:05

The results were still confusing but consistent. 

1. With profits or losses on a EURGBP long trade, the GBPUSD ASK was used to convert the profits and the losses.

2. WIth profits or losses on a EURCAD long trade, the USDCAD BID was used to convert the profits and the losses.

The wrong statement was marked in yellow.

The price type (BID/ASK) of the profit/account conversion pair depends to two things: (a) the type of the order (b) position of account currency in the conversion pair (first or second).

It is a simple rule: The trade type on the conversion pair is the same as that of the traded pair.

On a trading account in USD:

  • For Buy orders (EURGBP) and direct conversion cross (GBPUSD) ->    buy the cross: Ask is used.
  • For Buy orders (EURCAD) and indirect conversion cross (USDCAD) -> buy the cross: 1/Bid (indirect)
  • For Sell orders (EURGBP) and direct conversion cross (GBPUSD) ->    sell the cross: Bid is used.
  • For Sell orders (EURCAD) and indirect conversion cross (USDCAD) -> sell the cross: 1/Ask (indirect)
Forex Calculators
Forex Calculators
  • www.mql5.com
Margin Calculator, Point Value Calculator, Position Size Calculator, Profit Calculator and Swap Calculator.
 
amrali #:

Edit:

Alain, was wrong from the start of the discussion.

Yes, I was wrong.

I am also having no explanation for your trade @Alain Verleyen. I told you before it is contradictory to my previous tests.

But you are wrong too because a theory which doesn't explain all facts is just wrong. It's not just one trade, on this account using EUR, applying your logic gives me :

CheckHistoryTrades (AUDNZD,M1)    Checked: 42, No match in profit: 14, in loss: 19

132 trades were checked but most of them I didn't take them into account because the difference is insignificant (small volume, very small difference between bid and ask), it gives the same profit after rounding using bid or ask.

33 trades do not match the logic you applied which is :

BUY => 1/Bid, SELL => 1/Ask.

But as the trade I showed previously they follow the opposite logic :

BUY => 1/Ask, SELL => 1/Bid.

So yes, I was wrong, I was lead in error by my experience as I knew from practice your logic was not right (in all cases), and as Metaquotes CEO talked himself about using PROFIT/LOSS, I draw wrong conclusion without checking all situations.

This needs more investigation.

 
amrali #:

The wrong statement was marked in yellow.

The price type (BID/ASK) of the profit/account conversion pair depends to two things: (a) the type of the order (b) position of account currency in the conversion pair (first or second).

It is a simple rule: The trade type on the conversion pair is the same as that of the traded pair.

On a trading account in USD:

  • For Buy orders (EURGBP) and direct conversion cross (GBPUSD) ->    buy the cross: Ask is used.
  • For Buy orders (EURCAD) and indirect conversion cross (USDCAD) -> buy the cross: 1/Bid (indirect)
  • For Sell orders (EURGBP) and direct conversion cross (GBPUSD) ->    sell the cross: Bid is used.
  • For Sell orders (EURCAD) and indirect conversion cross (USDCAD) -> sell the cross: 1/Ask (indirect)
Alain Verleyen #:

Yes, I was wrong.

But you are wrong too because a theory which doesn't explain all facts is just wrong. It's not just one trade, on this account using EUR, applying your logic gives me :

CheckHistoryTrades (AUDNZD,M1)    Checked: 42, No match in profit: 14, in loss: 19

132 trades were checked but most of them I didn't take them into account because the difference is insignificant (small volume, very small difference between bid and ask), it gives the same profit after rounding using bid or ask.

33 trades do not match the logic you applied which is :

BUY => 1/Bid, SELL => 1/Ask.

But as the trade I showed previously they follow the opposite logic :

BUY => 1/Ask, SELL => 1/Bid.

So yes, I was wrong, I was lead in error by my experience as I knew from practice your logic was not right (in all cases), and as Metaquotes CEO talked himself about using PROFIT/LOSS, I draw wrong conclusion without checking all situations.

This needs more investigation.

The system I described where I give a total of 7 rules seems to have consistent logic Alain (theory that explains all facts) except if you try to understand the outlier trades you have in your history.

The logic is simply like Amrali stated: The trade type on the conversion pair is the same as that of the traded pair.

Add to that that the conversion is done with the close price that goes with the trade type, so if you close a long, you use the bid, and if you close a short, you use the ask.

Add to that that if the your account currency is the quote currency in your conversion pair (ex: converting profit for a EURGBP trade on a USD account, the conversion pair is GBPUSD), then you simply want to invert all the rules because you want to act like if you are using USDGBP's rate instead of GBPUSD's. (so shorts becomes longs and asks become bids).

To me that's good logic, and by the way I will never use the built-in tick value variables to calculate my position size for 2 reasons: 1) the name of the variables make it confusing and 2) all rules except #6 and #7 allow you to calculate the exact loss values with the future close price while the built in variables use the current quote (not the future quote) so it's not going to be the exact value anyways so I see no reasons to use those variables now.

One last thing, Amrali says I made an error in my rules, but that's how my broker operates, all these rules have been tested on a demo account with 100% accuracy. I recommend you try testing the rules with a different technique to avoid synchronization biais in your rate's history. Use a demo, open a position for 1 lot, place a stop loss 1000 points away from the entry price, then hover over the stop while at the exact same time the pop-up appears (that tells you the loss value) take a screenshot so that you can see exactly what the server says the loss will be with that stop while also seeing exactly what are the bid and ask on the conversion pair (keep your market watch open so that you see the rates in the screenshot).

With this kind of test, you should be able to confirm every rule from 1 to 7. If they don't match, then I'll have no choice but to think that each broker may opperate differently because all the rules are confirmed to be valid with my current broker.

 
Jeepack #:

The system I described where I give a total of 7 rules seems to have consistent logic Alain (theory that explains all facts) except if you try to understand the outlier trades you have in your history.

The logic is simply like Amrali stated: The trade type on the conversion pair is the same as that of the traded pair.

Add to that that the conversion is done with the close price that goes with the trade type, so if you close a long, you use the bid, and if you close a short, you use the ask.

Add to that that if the your account currency is the quote currency in your conversion pair (ex: converting profit for a EURGBP trade on a USD account, the conversion pair is GBPUSD), then you simply want to invert all the rules because you want to act like if you are using USDGBP's rate instead of GBPUSD's. (so shorts becomes longs and asks become bids).

To me that's good logic, and by the way I will never use the built-in tick value variables to calculate my position size for 2 reasons: 1) the name of the variables make it confusing and 2) all rules except #6 and #7 allow you to calculate the exact loss values with the future close price while the built in variables use the current quote (not the future quote) so it's not going to be the exact value anyways so I see no reasons to use those variables now.

One last thing, Amrali says I made an error in my rules, but that's how my broker operates, all these rules have been tested on a demo account with 100% accuracy. I recommend you try testing the rules with a different technique to avoid synchronization biais in your rate's history. Use a demo, open a position for 1 lot, place a stop loss 1000 points away from the entry price, then hover over the stop while at the exact same time the pop-up appears (that tells you the loss value) take a screenshot so that you can see exactly what the server says the loss will be with that stop while also seeing exactly what are the bid and ask on the conversion pair (keep your market watch open so that you see the rates in the screenshot).

With this kind of test, you should be able to confirm every rule from 1 to 7. If they don't match, then I'll have no choice but to think that each broker may opperate differently because all the rules are confirmed to be valid with my current broker.

Outlier trades ?

You can't just discard the data which doesn't satisfy your theory. According to history data provided by the platform and the broker, it is what is is, there is no synchronization issue (beside the fact I double checked) because when using the bid doesn't match, using the ask perfectly matches. A wrong tick (bid/ask) could not do that.

Anyway, I don't have an explanation for these facts (EUR account ? real account ? something else ?). I will investigate further.

Thanks for your topic which forced us to dig more deeply. Thanks to amrali. I am glad I learnt new things.

Reason: