currency convertion

 
Hi all,

How can write a function which converts a price in currency into an other currency ?
For exemple converting 38 EUR into AUD...
Is an mql5 function exists ?
Thanks,
Erwann.
 
38 EUR ÷ EURAUD = 38 ÷ 1.56940 = 24.21 AUD
 
William Roeder #:
38 EUR ÷ EURAUD = 38 ÷ 1.56940 = 24.21 AUD
It was an example...
My aim is to convert XXX to YYY.
 
Erwann Pannerec #:
It was an example...
My aim is to convert XXX to YYY.

For example, XXX to AUD

double price_aud = 38 * ExchangeRate("EUR");

//+------------------------------------------------------------------+
double ExchangeRate(string currency)    //xxx to AUD
{
   double ret_rate = -1.0;

   if (currency == "AUD")
      ret_rate = 1.00;
   else if (currency == "CAD")
      ret_rate = 1.00 / iClose("AUDCAD" + symbol_suffix, PERIOD_D1, 0);
   else if (currency == "CHF")
      ret_rate = 1.00 / iClose("AUDCHF" + symbol_suffix, PERIOD_D1, 0);
   else if (currency == "EUR")
      ret_rate = iClose("EURAUD" + symbol_suffix, PERIOD_D1, 0);
   else if (currency == "GBP")
      ret_rate = iClose("GBPAUD" + symbol_suffix, PERIOD_D1, 0);
   else if (currency == "JPY")
      ret_rate = 1.00 / iClose("AUDJPY" + symbol_suffix, PERIOD_D1, 0);
   else if (currency == "NZD")
      ret_rate = 1.00 / iClose("AUDNZD" + symbol_suffix, PERIOD_D1, 0);
   else if (currency == "USD")
      ret_rate = 1.00 / iClose("AUDUSD" + symbol_suffix, PERIOD_D1, 0);

   return (ret_rate);
}
//+-------------------------------------------------------------------+
 

There is no MT function to convert currencie rates, it has to be custom . Find out the path from input currency to output currency and multiply or divide by the appropriate rate, there should be no more than 3 steps .

 
William Roeder #:
38 EUR ÷ EURAUD = 38 ÷ 1.56940 = 24.21 AUD
Which is incorrect. You need to multiply.
 
Alain Verleyen #: Which is incorrect. You need to multiply.

EUR / (EUR/AUD) = AUD

 
William Roeder #:

EUR / (EUR/AUD) = AUD

Wrong.
 
Nagisa Unada #:

For example, XXX to AUD

Which is also incorrect. When you use a "reverse" symbol (so when you divide), you need to use the ask price. iClose() always returns the bid.

See https://www.mql5.com/en/forum/367457/page3#comment_21903583

TICK_VALUE for non account currency pair
TICK_VALUE for non account currency pair
  • 2021.04.18
  • www.mql5.com
I need to calculate tick value for currecy pair that does not include account currency, but getting different from defult SymbolInfoDouble(symbol...
Reason: