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(
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.
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+voidOnStart()
{
conststring symbol = "EURGBP"; //-symbol of interest//-MQL5 default method for calculating TICK_VALUE:constdouble expected = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_VALUE);
//-my method to calculate TICK_VALUE:constdouble result = GetTickValue(symbol);
Print("tickvalue expected: ", expected, " result: ", result);
if(MathAbs(result - expected) > 0.00001)
Print("test failed!");
elsePrint("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)
{
conststring prof = SymbolInfoString(symbol, SYMBOL_CURRENCY_PROFIT);
conststring acc = AccountInfoString(ACCOUNT_CURRENCY); //-account currency//--- TickValue (in account currency) = price delta * number of units per lot * profit/account exchange rateconstdouble 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-insensitiveif(StringCompare(curr_prof, curr_acc, false) == 0)
{
return (1.0);
}
//--- symbol suffix of the current chart symbolstring 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 watchdouble 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 watchdouble 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 MarketWatchif(!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);
}
}
//--- succeedreturn(true);
}
//+------------------------------------------------------------------+
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!
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
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
Thanks for your effort. Seems it's not Bid/Ask problem. Looks like I miss some magic ingredient(
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
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:
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:
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).
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:
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!
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.