TICK_VALUE for non account currency pair - page 2

 
Fernando Carreiro:

Yes, that is correct! I also tried all the combinations, including with Mid Price, both on MetaTrader 4 and 5 but it is closest on MetaTrader 4 and worse on MetaTrader 5

MetaTrader 5:

MetaTrader 4:

Thanks for your effort. Seems it's not Bid/Ask problem. Looks like I miss some magic ingredient(

 
Fernando Carreiro:

If I follow the logic in your code, you are applying the following logic - Is this correct?

I'm using this:

https://www.mql5.com/en/forum/40812#comment_18929033

and this:

https://www.thebalance.com/calculating-pip-value-in-forex-pairs-1031022

How to calculate pip value in currency account (USD, EUR etc) some bars ago or some time ago?
How to calculate pip value in currency account (USD, EUR etc) some bars ago or some time ago?
  • 2015.02.15
  • www.mql5.com
Hi, Using SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE) I can get pip value only for current time but I cannot do it in past...
 
terminalstat:

I'm using this:

https://www.mql5.com/en/forum/40812#comment_18929033

and this:

https://www.thebalance.com/calculating-pip-value-in-forex-pairs-1031022

So, folowing my previous calculation logic and if I use the GBP/USD directly, I then get the correct answer with the BID price:

(EUR/USD) / (EUR/GBP) = (EUR/USD) * (GBP/EUR) = GBP/USD
2021.04.18 00:07:02.660 testtickvalue (EURGBP,H1)       EURUSD/EURGBP BID/BID - tickvalue expected: 1.38383000 result: 1.38445271
2021.04.18 00:07:02.660 testtickvalue (EURGBP,H1)       EURUSD/EURGBP BID/ASK - tickvalue expected: 1.38383000 result: 1.38371717
2021.04.18 00:07:02.660 testtickvalue (EURGBP,H1)       EURUSD/EURGBP ASK/BID - tickvalue expected: 1.38383000 result: 1.38486873
2021.04.18 00:07:02.660 testtickvalue (EURGBP,H1)       EURUSD/EURGBP ASK/ASK - tickvalue expected: 1.38383000 result: 1.38413296
2021.04.18 00:07:02.660 testtickvalue (EURGBP,H1)       EURUSD/EURGBP MID/MID - tickvalue expected: 1.38383000 result: 1.38429279
2021.04.18 00:07:02.660 testtickvalue (EURGBP,H1)       GBPUSD BID: 1.38383000, ASK: 1.38462000
EDIT: In other words, it is just as stated in the other thread I referenced, namely Profit Currency vs Account currency!
 

In other words the correct calculation would be:

const double result = SymbolInfoDouble(prof + acc, SYMBOL_BID);
Or the inverse of this if such a currency pair does not exist and only its inverse!
 
I think maybe why the other method did not work, was because it is the weekend and there is probably some arbitrage at play at the moment, which many traders like to exploit when they have razor thin spreads at their disposal (which we retail traders don't have access to).
 
Fernando Carreiro:
I think maybe why the other method did not work, was because it is the weekend and there is probably some arbitrage at play at the moment, which many traders like to exploit when they have razor thin spreads at their disposal (which we retail traders don't have access to).

That makes sence, I'll try it on Monday. Thanks for your efforts!

 
terminalstat: That makes sence, I'll try it on Monday. Thanks for your efforts!

There is no need to wait for Monday! Just use the simplest and direct method of "prof + acc", because arbitrage can occur at any time, even during the week.

Just as explained in the other thread - its Profit Currency vs. Account currency. No need to use a Triangular calculation, when you can just read a currency pair directly.

 

Try this code to calculate the tick_value:

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart()
  {
   const string symbol = "EURGBP"; //-symbol of interest

//-MQL5 default method for calculating TICK_VALUE:
   const double expected = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_VALUE);

//-my method to calculate TICK_VALUE:
   const double result = GetTickValue(symbol);

   Print("tickvalue expected: ", expected, " result: ", result);

   if(MathAbs(result - expected) > 0.00001)
      Print("test failed!");
   else
      Print("test pass OK");
  }
//+------------------------------------------------------------------+
//output:
/*
2021.04.18 03:14:36.195 TickValue (XAUUSD,M5)   tickvalue expected: 1.38404 result: 1.38404
2021.04.18 03:14:36.195 TickValue (XAUUSD,M5)   test pass OK
*/

//+------------------------------------------------------------------+
//| Calculate the value of one tick per lot in the account currency. |
//+------------------------------------------------------------------+
double GetTickValue(string symbol)
  {
   const string prof = SymbolInfoString(symbol, SYMBOL_CURRENCY_PROFIT);
   const string acc  = AccountInfoString(ACCOUNT_CURRENCY); //-account currency

//--- TickValue (in account currency) = price delta * number of units per lot * profit/account exchange rate
   const double tick_value =
      SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE)
      * SymbolInfoDouble(symbol, SYMBOL_TRADE_CONTRACT_SIZE)
      * CrossRate(prof, acc);

   if(tick_value == 0)
     {
      Print(__FUNCTION__, ": Error, cannot get tick value for ", symbol);
     }

   return (tick_value);
  }
//+------------------------------------------------------------------+
//| Get the cross-rate for the profit/account symbol                 |
//+------------------------------------------------------------------+
double CrossRate(string curr_prof, string curr_acc)
  {
//--- compare case-insensitive
   if(StringCompare(curr_prof, curr_acc, false) == 0)
     {
      return (1.0);
     }

//--- symbol suffix of the current chart symbol
   string symbol_suffix = StringSubstr(Symbol(), 6, StringLen(Symbol())-6);
//---
   string symbol = curr_prof + curr_acc + symbol_suffix;
   if(CheckMarketWatch(symbol))
     {
      //--- if symbol is in the market watch
      double cross_rate = SymbolInfoDouble(symbol, SYMBOL_BID);
      if(cross_rate != 0.0)
        {
         return (cross_rate);
        }
     }
//--- Try the inverse symbol
   symbol = curr_acc + curr_prof + symbol_suffix;
   if(CheckMarketWatch(symbol))
     {
      //--- if symbol is in the market watch
      double cross_rate = SymbolInfoDouble(symbol, SYMBOL_BID);
      if(cross_rate != 0.0)
        {
         return (1 / cross_rate);
        }
     }
//---
   Print(__FUNCTION__, ": Error, cannot get cross rate for ", curr_prof + curr_acc);
   return (0.0);
  }
//+------------------------------------------------------------------+
//| Checks if symbol is selected in the MarketWatch                  |
//| and adds symbol to the MarketWatch, if necessary                 |
//+------------------------------------------------------------------+
bool CheckMarketWatch(string symbol)
  {
//--- check if symbol is selected in the MarketWatch
   if(!SymbolInfoInteger(symbol,SYMBOL_SELECT))
     {
      if(GetLastError()==ERR_MARKET_UNKNOWN_SYMBOL)
        {
         printf(__FUNCTION__+": Unknown symbol '%s'",symbol);
         return(false);
        }
      if(!SymbolSelect(symbol,true))
        {
         printf(__FUNCTION__+": Error adding symbol %d",GetLastError());
         return(false);
        }
     }
//--- succeed
   return(true);
  }
//+------------------------------------------------------------------+
 
Fernando Carreiro:

There is no need to wait for Monday! Just use the simplest and direct method of "prof + acc", because arbitrage can occur at any time, even during the week.

Just as explained in the other thread - its Profit Currency vs. Account currency. No need to use a Triangular calculation, when you can just read a currency pair directly.

God, I love this community!

Thank's Fernando, your method is really great. Thank's for pointing out. I've been messing with this stuff for two days to discover that so simple solution you did in an hour. You are the best!

 
amrali:

Try this code to calculate the tick_value:

Dear amrali, it's very impressive! You are doing my job, I owe you a beer) Thanks!

Now we have an elegant and nice solution for all others searching for this stuff.