Forum on trading, automated trading systems and testing trading strategies
P&L calculation formula for different traded assets
Fernando Carreiro, 2023.05.04 14:53
I suggest reading up on the following two MQL5 trade functions ...
Calculates the margin required for the specified order type, in the deposit currency
Calculates the profit based on the parameters passed, in the deposit currency
They calculate the margin and the profit/loss respectively, adjusting automatically for the asset type, making it unnecessary to calculate it manually using the methods you have described.
They do however, not include Commission or Swaps. Those are only provided after the fact and are accessible via other functionality — Documentation on MQL5: Trade Functions
Thanks @Fernando Carreiro for a super quick reply. I will explore your suggestion.
Additionally, I just come across code from one of the tutorials as below
string BaseCurrency() { return ( AccountInfoString( ACCOUNT_CURRENCY ) ); } double Point( string symbol ) { return ( SymbolInfoDouble(vQSymbolC , SYMBOL_POINT ) ); } double TickSize( string symbol ) { return ( SymbolInfoDouble( vQSymbolC , SYMBOL_TRADE_TICK_SIZE ) ); } double TickValue( string symbol ) { return ( SymbolInfoDouble( vQSymbolC , SYMBOL_TRADE_TICK_VALUE ) ); } double pointValue = PointValue( vQSymbolC );
when running it, I found that it returns the Exchange Rate .... which can than be used to multiply.
2023.05.04 20:09:23.719 RiskValue (US30,D1) Account Currency[USD] and Quote Symbol is [GBPUSD] 2023.05.04 20:09:23.719 RiskValue (US30,D1) tickSize=0.000010, tickValue=1.000000, point=0.000010, ticksPerPoint=1.000000, pointValue=1.000000 2023.05.04 20:09:23.719 RiskValue (US30,D1) ExchangeRate(ValuePerPoint) for QuoteSymbol[GBPUSD] to BaseCurrency[USD][1.00000] 2023.05.04 20:09:23.719 RiskValue (US30,D1) TradeRisk(RiskAmount)[USD][45.00] for trading LotSize[0.60] of QuoteSymbol[GBPUSD] with risk of [75.0] points 2023.05.04 20:09:23.719 RiskValue (US30,D1) StopLoss(RiskInSLPoints)[166] for trading[GBPUSD] LotSize[0.60] placing USD[100.00] at risk 2023.05.04 20:09:23.719 RiskValue (US30,D1) OptimumLotSize[2.00] for Risk of [GBPUSD][100.00] and StopLoss Points[50.00000] 2023.05.04 20:09:23.719 RiskValue (US30,D1) Account Currency[USD] and Quote Symbol is [EURGBP] 2023.05.04 20:09:23.719 RiskValue (US30,D1) tickSize=0.000010, tickValue=1.258540, point=0.000010, ticksPerPoint=1.000000, pointValue=1.258540 2023.05.04 20:09:23.719 RiskValue (US30,D1) ExchangeRate(ValuePerPoint) for QuoteSymbol[EURGBP] to BaseCurrency[USD][1.25854] 2023.05.04 20:09:23.719 RiskValue (US30,D1) TradeRisk(RiskAmount)[USD][56.63] for trading LotSize[0.60] of QuoteSymbol[EURGBP] with risk of [75.0] points 2023.05.04 20:09:23.719 RiskValue (US30,D1) StopLoss(RiskInSLPoints)[132] for trading[EURGBP] LotSize[0.60] placing USD[100.00] at risk 2023.05.04 20:09:23.719 RiskValue (US30,D1) OptimumLotSize[1.59] for Risk of [EURGBP][100.00] and StopLoss Points[50.00000] 2023.05.04 20:09:23.719 RiskValue (US30,D1) Account Currency[USD] and Quote Symbol is [UK100] 2023.05.04 20:09:23.719 RiskValue (US30,D1) tickSize=0.100000, tickValue=0.125854, point=0.100000, ticksPerPoint=1.000000, pointValue=0.125854 2023.05.04 20:09:23.719 RiskValue (US30,D1) ExchangeRate(ValuePerPoint) for QuoteSymbol[UK100] to BaseCurrency[USD][0.12585] 2023.05.04 20:09:23.719 RiskValue (US30,D1) TradeRisk(RiskAmount)[USD][5.66] for trading LotSize[0.60] of QuoteSymbol[UK100] with risk of [75.0] points 2023.05.04 20:09:23.719 RiskValue (US30,D1) StopLoss(RiskInSLPoints)[1324] for trading[UK100] LotSize[0.60] placing USD[100.00] at risk 2023.05.04 20:09:23.719 RiskValue (US30,D1) OptimumLotSize[15.89] for Risk of [UK100][100.00] and StopLoss Points[50.00000] 2023.05.04 20:09:23.719 RiskValue (US30,D1) Account Currency[USD] and Quote Symbol is [GER40] 2023.05.04 20:09:23.719 RiskValue (US30,D1) tickSize=0.100000, tickValue=0.110270, point=0.100000, ticksPerPoint=1.000000, pointValue=0.110270 2023.05.04 20:09:23.719 RiskValue (US30,D1) ExchangeRate(ValuePerPoint) for QuoteSymbol[GER40] to BaseCurrency[USD][0.11027] 2023.05.04 20:09:23.719 RiskValue (US30,D1) TradeRisk(RiskAmount)[USD][4.96] for trading LotSize[0.60] of QuoteSymbol[GER40] with risk of [75.0] points 2023.05.04 20:09:23.719 RiskValue (US30,D1) StopLoss(RiskInSLPoints)[1511] for trading[GER40] LotSize[0.60] placing USD[100.00] at risk 2023.05.04 20:09:23.719 RiskValue (US30,D1) OptimumLotSize[18.14] for Risk of [GER40][100.00] and StopLoss Points[50.00000]
I did checked these exchange rates on Xe Currency Converter App and results seems to be almost same.
Can I use this also as right approach to convert my currencies and with OrderCalcProfit() ...
Hi Fernando, it seems you took my question "
- I have seen Margin Currency and Profit Currency in Brokers terminal, how can I access these value?
in a different direction
What I meant was that can I use this methods to find currency of Traded Symbol e.g. GER40 (DAX40) which my broker's terminal says Margin Currency and Profit Currency EUR.
@Fernando Carreiro
Hi Fernando, it seems you took my question "
- I have seen Margin Currency and Profit Currency in Brokers terminal, how can I access these value?
in a different direction
What I meant was that can I use this methods to find currency of Traded Symbol e.g. GER40 (DAX40) which my broker's terminal says Margin Currency and Profit Currency EUR.
For function SymbolInfoString():
Identifier | Description | Type |
---|---|---|
SYMBOL_CURRENCY_BASE | Basic currency of a symbol | string |
SYMBOL_CURRENCY_PROFIT | Profit currency | string |
SYMBOL_CURRENCY_MARGIN | Margin currency | string |
For function SymbolInfoString():
Identifier | Description | Type |
---|---|---|
SYMBOL_CURRENCY_BASE | Basic currency of a symbol | string |
SYMBOL_CURRENCY_PROFIT | Profit currency | string |
SYMBOL_CURRENCY_MARGIN | Margin currency | string |
Thanks Mohammed. Symbol_Currency_Base has helped to solve part of my problem. However the second part, how to covert its value to Account Base currency still remain challenge for me yet.
@Mohammed Abdulwadud Soubra
Thanks Mohammed. Symbol_Currency_Base has helped to solve part of my problem. However the second part, how to covert its value to Account Base currency still remain challenge for me yet.
Please stop posting in this section.
This section is about trading system, not about coding unless it's directly related to a trading strategy.
I will move this topic.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Dear all,
In reference to this tutorial at https://www.youtube.com/watch?v=TAzM5Vd9nLs where I need to convert Symbol values into my accounts currency.
I am looking to resolve the following:
I have tried to look on the forum, but could not found a solution, though some articles were on the same topic.
Looking forward to hear back from experts.