how to obtain exchange rate symbol

 

Hi to all,

i need to get symbol'es exchange rate different to my account currency.

Example, my account currency is USD i want trade Dax Index in EUR.

How need to convert eur to usd to calculate stop loss.

There is a mql4 function? how do this?

Thanks in advance.

 
eugleo76: i need to get symbol'es exchange rate different to my account currency. Example, my account currency is USD i want trade Dax Index in EUR. How need to convert eur to usd to calculate stop loss. There is a mql4 function? how do this?

There is no predefined function. You have to code the calculations yourself.

For your example, you need to lookup the EUR/USD symbol values and carry out the conversion calculations.

 

thank you so much.

So, when i open a position, lookup eurusd, make conversion and that is exchange rate.

And how many decimal digit takes? 2 or more?

 
eugleo76 #: So, when i open a position, lookup eurusd, make conversion and that is exchange rate. And how many decimal digit takes? 2 or more?

No, it is not that simple, you have to consider which currency is being "bought" and which is being "sold" so as to decide if it is the bid or the ask price that should be used for the conversion. Please do some research on currency conversion.

All the decimal digits should be used in the calculations. It is only in the final part when you apply the open and close prices (S/L, T/P, etc.), that you should then align the price to the symbol's tick size.

 
Fernando Carreiro #:
No, it is not that simple, you have to consider which currency is being "bought" and which is being "sold" so as to decide if it is the bid or the ask price that should be used for the conversion.

ok..let me an example.

i have usd account currency, and i bought dax index, Ineed to use eurusd ask price.

if i want sell dax index I need to use eurusd bid price to conversion.

right?

 
eugleo76 #: ok..let me an example. i have usd account currency, and i bought dax index, Ineed to use eurusd ask price. if i want sell dax index I need to use eurusd bid price to conversion. right?

I think this is a XY problem. So, first ....

Why do you need, or want to trade the DAX in EUR if your account is in USD?

The tick value, is already expressed in account currency, so you should not need to convert anything if you want to calculate the risk for a particular stop-loss size.

You seem to want to complicate things. Please explain.

 
Fernando Carreiro #:

I think this is a XY problem. So, first ....

Why do you need, or want to trade the DAX in EUR if your account is in USD?

The tick value, is already expressed in account currency, so you should not need to convert anything if you want to calculate the risk for a particular stop-loss size.

You seem to want to complicate things. Please explain.

ok give you an example.

Account currency in EUR, crude oil (currency in USD) sell  open at 70.39, close at 71.12 and size is 0.10

I apply the following formula to calculate profit/loss:

(price open - price close) * (size * contract size) => (70.39 - 71.12) * (0.10 * 1000) => -73$.

MT$ said -67.91€ and it's correnct -73 * 0.93 = -67.89

Something wrong in my calculations?

 
eugleo76 #:

ok give you an example.

Account currency in EUR, crude oil (currency in USD) sell  open at 70.39, close at 71.12 and size is 0.10

I apply the following formula to calculate profit/loss:

(price open - price close) * (size * contract size) => (70.39 - 71.12) * (0.10 * 1000) => -73$.

MT$ said -67.91€ and it's correnct -73 * 0.93 = -67.89

Something wrong in my calculations?

You don't need to do that. The "Tick Value" provided by system will already be expressed in the account currency. It does the conversion for you.

The only time that may not happen is when a broker has not properly set it up, in which case you will need to discuss it with them to have it fixed.

So, learn to use the "tick value" and "tick size" in your calculations instead.

Symbol Properties - Environment State - Constants, Enumerations and Structures - MQL4 Reference

SYMBOL_TRADE_TICK_VALUE

Value of SYMBOL_TRADE_TICK_VALUE_PROFIT

double

SYMBOL_TRADE_TICK_SIZE

Minimal price change

double

Symbol Properties - Environment State - Constants, Enumerations and Structures - MQL4 Reference
Symbol Properties - Environment State - Constants, Enumerations and Structures - MQL4 Reference
  • docs.mql4.com
Symbol Properties - Environment State - Constants, Enumerations and Structures - MQL4 Reference
 

Here is some information that can help explain how to use Tick Value and Size ...

Forum on trading, automated trading systems and testing trading strategies

How to calculate take profit from currency

Fernando Carreiro, 2022.09.05 17:00

These are all the same equation written in different ways ...

[Volume]      = [Money Value] * [Tick Size] / ( [Tick Value] * [Stop Size] )
[Stop Size]   = [Money Value] * [Tick Size] / ( [Tick Value] * [Volume]    )
[Money Value] = [Volume]      * [Stop Size] * [Tick Value]   / [Tick Size]

[Volume] in lots
[Stop Size] in quote price change
[Money Value] in account currency

Forum on trading, automated trading systems and testing trading strategies

How to calculate proper lot size ?

Fernando Carreiro, 2022.02.11 19:28

This is untested, uncompiled code, only to serve as a guide for you to further study and implement depending on your own requirements ...

// Calculate Max Lot Size based on Maximum Risk
double dblLotsRisk( double dbStopLoss, double dbRiskRatio )
{
   double
      dbLotsMinimum  = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_MIN       ),
      dbLotsMaximum  = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_MAX       ),
      dbLotsStep     = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_STEP      ),
      dbTickSize     = SymbolInfoDouble( _Symbol, SYMBOL_TRADE_TICK_SIZE  ),
      dbTickValue    = SymbolInfoDouble( _Symbol, SYMBOL_TRADE_TICK_VALUE ),
      dbValueAccount = fmin( fmin( 
                       AccountInfoDouble( ACCOUNT_EQUITY      )  , 
                       AccountInfoDouble( ACCOUNT_BALANCE     ) ),
                       AccountInfoDouble( ACCOUNT_MARGIN_FREE ) ),
      dbValueRisk    = dbValueAccount * dbRiskRatio,
      dbLossOrder    = dbStopLoss * dbTickValue / dbTickSize,
      dbCalcLot      = fmin(  dbLotsMaximum,                  // Prevent too greater volume
                       fmax(  dbLotsMinimum,                  // Prevent too smaller volume
                       round( dbValueRisk / dbLossOrder       // Calculate stop risk
                       / dbLotsStep ) * dbLotsStep ) );       // Align to step value

   return ( dbCalcLot );
};

 
Fernando Carreiro #:

You don't need to do that. The "Tick Value" provided by system will already be expressed in the account currency. It does the conversion for you.

The only time that may not happen is when a broker has not properly set it up, in which case you will need to discuss it with them to have it fixed.

So, learn to use the "tick value" and "tick size" in your calculations instead.

Symbol Properties - Environment State - Constants, Enumerations and Structures - MQL4 Reference

SYMBOL_TRADE_TICK_VALUE

Value of SYMBOL_TRADE_TICK_VALUE_PROFIT

double

SYMBOL_TRADE_TICK_SIZE

Minimal price change

double

Thank's Fernando,

then I need to use SYMBOL_TRADE_TICK_VALUE to find current exchange rate.

If I am trading usd Symbol and currency account is EUR currency exchange rate is ;

double tickValue = SymbolInfoDouble("EURUSD",SYMBOL_TRADE_TICK_VALUE);


Right?

 
eugleo76 #: then I need to use SYMBOL_TRADE_TICK_VALUE to find current exchange rate ... Right?

No! The "tick value" is the value of a single price tick expressed in the account currency. So, there is no need to apply a conversion (that is, if the broker is doing it correctly, which sometimes they don't).

For example, take the symbol XAUUSD with a tick size of 0.01

  • For an account currency of USD, the tick value will be 1.00000
  • For an account currency of EUR, the tick value will be 0.92620 (depends on the current exchange rate)

As for DE40, or Euro STOXX50, and others, many brokers do not properly apply the correct tick value for the price tick, so you will have to check if it is the case with your broker.

Only in these special "bad" broker cases will you have to carry out a currency conversion using the current EURUSD bid/ask price (not the tick value), to convert it to/from your USD account currency.