Difficulties converting from any symbol's currency to account currency

 

Hi All,


Hope you are all well. I've gone through some of the topics here to find a few suggestions to solve this problem which I'm sure many have come across.

I'm finding that converting a symbol's profit currency to account currency is way more difficult than expected to be.

I've come across a suggestion by some of the more experienced fellows here regarding using TICKVALUE or it's equivalent in MQL5 (I don't see MODE_TICKVALUE available).

I've come across another suggestion saying that this does not work on all symbols with all brokers so I am left pondering in as to what I can do.


So far, I feel the consideration I have is to just have an array of symbol to symbol and do the calculation like that but I feel this is a little manual and probably not ideal.


I seek to ask for  a reliable means to convert profit currency to symbol currency by just knowing a symbol and a price; Where can I start looking to achieve this please? This does not have to; nor will it, depend on an existing position or order.



Thanks


Duncan

 
dnc77:

Hi All,


Hope you are all well. I've gone through some of the topics here to find a few suggestions to solve this problem which I'm sure many have come across.

I'm finding that converting a symbol's profit currency to account currency is way more difficult than expected to be.

I've come across a suggestion by some of the more experienced fellows here regarding using TICKVALUE or it's equivalent in MQL5 (I don't see MODE_TICKVALUE available).

I've come across another suggestion saying that this does not work on all symbols with all brokers so I am left pondering in as to what I can do.


So far, I feel the consideration I have is to just have an array of symbol to symbol and do the calculation like that but I feel this is a little manual and probably not ideal.


I seek to ask for  a reliable means to convert profit currency to symbol currency by just knowing a symbol and a price; Where can I start looking to achieve this please? This does not have to; nor will it, depend on an existing position or order.



Thanks


Duncan

Yes, this is indeed not as easy, or obvious to achieve.

One suggestion I can give, try to use this function to calculate the tick value of the symbol in account currency.


If you need a different currency than your account currency, you need to do the calculations yourself. For that, you need to dig into this:


And especially the section:

ENUM_SYMBOL_CALC_MODE.

It has all relevant formulas documented.
 
Dominik Egert #:
Yes, this is indeed not as easy, or obvious to achieve.

One suggestion I can give, try to use this function to calculate the tick value of the symbol in account currency.


If you need a different currency than your account currency, you need to do the calculations yourself. For that, you need to dig into this:


And especially the section:

ENUM_SYMBOL_CALC_MODE.

It has all relevant formulas documented.
Thanks again Dominik.
 
I used this code

//+------------------------------------------------------------------+
//|                CURRENCY ADJUSTER                                 |
//+------------------------------------------------------------------+
double f_currency_changer(double value){

   double ts = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE)*10;
   double cs = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_CONTRACT_SIZE);
   if(ts<=0.0 || cs<=0.0) return 0.0;

   double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
   double last= SymbolInfoDouble(_Symbol, SYMBOL_LAST);
   double open = (ask>0.0 ? ask : (last>0.0 ? last : 0.0));
   if(open<=0.0) return 0.0;

   double close = open + ts;

   // Usa el mínimo volumen permitido (resultado luego se normaliza por volumen)
   double vol = fmax(10.0,SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN));

   double profit = 0.0;
   if(!OrderCalcProfit(ORDER_TYPE_BUY, _Symbol, vol, open, close, profit)){
      // Fallback: prueba SELL con -ts
      close = open - ts;
      if(!OrderCalcProfit(ORDER_TYPE_SELL, _Symbol, vol, open, close, profit))
         return value;
   }

   double ppl = profit / vol;         // PnL en cuenta por lot
   double r   = MathAbs(ppl) / (ts * cs);  // account_per_pnl_unit
   return value / r;
}/*++++++++++++++++++++++++++++++++++++++++++++++++++++++*/