Exact Calculation of P&L for MetaTrader Instruments with a different Base and Profit currency.

To add comments, please log in or register
Mark Wilson
859
Mark Wilson  

At the moment, it is the weekend, I don't have any positions open and cannot trade on my demo account, so cannot thoroughly evaluate any theories.   Does anybody know the exact method in which MetaTrader converts the profit into the account currency for an instrument where the account, base and profit currency are different.


For example, lets say I have a GBP account and have traded EURUSD.   The base and profit currencies are EUR and USD.   How does  it convert the USD profit into GBP Profit.   Does it use the GBPUSD mid ?   Does it use the GBPUSD bid or ask depending upon if the account is in profit or in loss ?   Does it use another method ?


Thanks for the help.


Mark

Meng Yin Teoh
2155
Meng Yin Teoh  
Mark100:

At the moment, it is the weekend, I don't have any positions open and cannot trade on my demo account, so cannot thoroughly evaluate any theories.   Does anybody know the exact method in which MetaTrader converts the profit into the account currency for an instrument where the account, base and profit currency are different.


For example, lets say I have a GBP account and have traded EURUSD.   The base and profit currencies are EUR and USD.   How does  it convert the USD profit into GBP Profit.   Does it use the GBPUSD mid ?   Does it use the GBPUSD bid or ask depending upon if the account is in profit or in loss ?   Does it use another method ?


Thanks for the help.


Mark


To covert from USD to GBP, you are basically sell USD to buy GBP. In other words, you are buying GBPUSD. Since you always sell at bid and buy at ask, therefore you use ask price in your case.

However, there is not much difference for small amount of money if you use either bid or ask for buy or sell. Usually I just use bid price to simplify my calculation.

Mark Wilson
859
Mark Wilson  
Meng Yin Teoh:


To covert from USD to GBP, you are basically sell USD to buy GBP. In other words, you are buying GBPUSD. Since you always sell at bid and buy at ask, therefore you use ask price in your case.

However, there is not much difference for small amount of money if you use either bid or ask for buy or sell. Usually I just use bid price to simplify my calculation.

Thanks for the response

If I had a positive P&L in dollars, I assume that I would sell dollars, but if my P&L was negative, I assume that I would buy dollars, so there are valid reasons for using bid or ask.   This technique does seem like a pain if the p&l switches betwern + and - frequently, which is why I suspected they may use mid or something else.

Thanks
whroeder1
17945
whroeder1  
Mark100: Does anybody know the exact method in which MetaTrader converts the profit into the account currency for an instrument where the account, base and profit currency are different.
Why do you care how, just do it.
  • You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
  • Account Balance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the SPREAD, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
  • Do NOT use TickValue by itself - DeltaPerLot
  • You must normalize lots properly and check against min and max.
  • You must also check FreeMargin to avoid stop out
Stanislav Korotky
24556
Stanislav Korotky  
Mark100:
Thanks for the response

If I had a positive P&L in dollars, I assume that I would sell dollars, but if my P&L was negative, I assume that I would buy dollars, so there are valid reasons for using bid or ask.   This technique does seem like a pain if the p&l switches betwern + and - frequently, which is why I suspected they may use mid or something else.

Actually this is a debatable question with very long story. MQ states, that you're right - they use ask or bid depending from positive or negative result. This is why they provide separate values - SYMBOL_TRADE_TICK_VALUE_PROFIT and SYMBOL_TRADE_TICK_VALUE_LOSS. Some other people say that ask or bid should have nothing to do with profit or loss in the trade, but solely depend from direction of the trade.

P.S. Here is a thead in Russian forum.

Alain Verleyen
36052
Alain Verleyen  
Stanislav Korotky:

Actually this is a debatable question with very long story. MQ states, that you're right - they use ask or bid depending from positive or negative result. This is why they provide separate values - SYMBOL_TRADE_TICK_VALUE_PROFIT and SYMBOL_TRADE_TICK_VALUE_LOSS. Some other people say that ask or bid should have nothing to do with profit or loss in the trade, but solely depend from direction of the trade.

P.S. Here is a thead in Russian forum.

There is not 1 solid argument in this discussion from the ones saying the pip value depends of the direction.
Mark Wilson
859
Mark Wilson  
whroeder1:
Why do you care how, just do it.
  • You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
  • Account Balance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the SPREAD, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
  • Do NOT use TickValue by itself - DeltaPerLot
  • You must normalize lots properly and check against min and max.
  • You must also check FreeMargin to avoid stop out

Thanks for the response.

Firstly, i'm not looking at placing stop losses.   I am trying to evaluate what kind of Gap risk a trade has, so I am looking at large movements, not small.

In your second calculation you are using DeltaPerLot, which I assume from your link, is referring to MarketInfo(.., MODE_TICKVALUE) / MarketInfo(...,MODE_TICKSIZE).

When you are dealing with profit currencies that are the same as the base currency (e.g. GBPUSD in a USD account), then this calculation is very easy and static.   However I don't know if you have noticed this, but when you are dealing with situations where the currencies in the book are very different (e.g. EURUSD in a GBP account), then MODE_TICKVALUE changes.   This then raises the question - how is MODE_TICKVALUE calculated and if you answer that question, you will probably answer my original question at the same time.  

In all likelihood is is probably a simple first order derivative calculation, converted into another currency using an fx rate.   You could ask yourself i) What is the size of the bump used when calculating MODE_TICKVALUE (TICKSIZE would be a sensible first guess) and what FX rate is used to convert MODE_TICKVALUE into the account currency.   The second answer is probably the same as my original question.

Why is there NO Complete EA within the Code-Base?
Why is there NO Complete EA within the Code-Base?
  • 2011.08.20
  • www.mql5.com
IMO, there appears to be no Complete EA within the mql4.com's Code-base or Articles for that matter of fact...
Mark Wilson
859
Mark Wilson  
whroeder1:
Why do you care how, just do it.
  • You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
  • Account Balance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the SPREAD, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
  • Do NOT use TickValue by itself - DeltaPerLot
  • You must normalize lots properly and check against min and max.
  • You must also check FreeMargin to avoid stop out


I have been trying to think of another way to express this.   Lets say you have a stock worth USD 100 and the ticksize is 1, then the TickValue is probably going to be 1.   However what happens when I convert that into GBP.


When I look at an fx trade for example, I know that the profit is going to be NoLots*LotSize*(Close-Open), but what I don't know is how that profit is converted into the account currency.   The reason that I am asking is that I got different results when comparing risk using the TICKVALUE/TICKSIZE calculation with some online risk calculators when I was looking at this on Friday and I wanted to understand the exact reasons for these differences.   I found the following section highlighting how the P&L is calculated:

https://www.mql5.com/en/docs/constants/environment_state/marketinfoconstants#enum_symbol_calc_mode

I can use this to double check my P&L calculations and compare them to websites, except for the fact that I don't know what rate is used.  

To me, it makes sense to compare my risk calculations to some external calculations and make sure that I can explain those differences properly.

Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Environment State / Symbol Properties - Reference on algorithmic/automated trading language for MetaTrader 5
Mohamad Zulhairi Baba
15919
Mohamad Zulhairi Baba  
Same calculation method used for, example USD base account, trade EURJPY. There many calculation example over the internet. Inverse that calculation.
Stanislav Korotky
24556
Stanislav Korotky  
Alain Verleyen:
There is not 1 solid argument in this discussion from the ones saying the pip value depends of the direction.

I'm not sure. One of alternative reasonings is the following.

Consider we want to buy EURGBP at moment X and then sell it at moment Y on USD account. Then

return (profit or loss) ~ eurgbp_bid_y * gbpusd_bid_y - eurgbp_ask_x * gbpusd_ask_x

or without crosses

return (profit or loss) ~ (eurusd_bid_y - eurusd_ask_x) + (gbpusd_ask_y - gbpusd_bid_x)

No matter if I win or lose, I must use ask to buy GBP for USD first then EUR for GBP at the entry and then use bid to sell EUR for GBP then sell GBP for USD at the exit. Profit or loss is just a difference between 2 operations in predefined directions. The directions will not change depending from profit or loss.

To add comments, please log in or register