SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE) sometimes zero

 

Hi guys,


need an advise.


I use tickvalue for calculating lot size.


Sometimes that piece of code returns zero:


tickVal = SymbolInfoDouble(Symbol(), SYMBOL_TRADE_TICK_VALUE);
tickVal = NormalizeDouble(tickVal, Digits());


I'm using tickValue to calculate Stopp Loss pips risked:


double Pips_Risked = SLPoints * tickVal;
Pips_Risked = NormalizeDouble(Pips_Risked, Digits());


Any idea why tickVal sometimes is empty? Same with SYMBOL_TRADE_TICK_VALUE_LOSS.


regards, Lukas

 
lukasp1:

Hi guys,


need an advise.


I use tickvalue for calculating lot size.


Sometimes that piece of code returns zero:



I'm using tickValue to calculate Stopp Loss pips risked:



Any idea why tickVal sometimes is empty? Same with SYMBOL_TRADE_TICK_VALUE_LOSS.


regards, Lukas

Hi,

Yes I’m having the same issue.  I’ve decided to test SYMBOL_TRADE_TICK_VALUE_PROFIT instead to see if that makes any difference in a real account.  

I’ll only know if it’s successful though if it doesn’t happen for 4 or 5 weeks. 

Cheers
 
David Rex Burrows #:
Hi,

Yes I’m having the same issue.  I’ve decided to test SYMBOL_TRADE_TICK_VALUE_PROFIT instead to see if that makes any difference in a real account.  

I’ll only know if it’s successful though if it doesn’t happen for 4 or 5 weeks. 

Cheers

Hi, thanks for your tip.


After reloading the EA, the correct tickValue has been read and the order has been created.


I've appended some debug information today in hoping to get more error details next time:


   for (int p = 0; p < 2; p++) {
   
      ResetLastError();
      tickVal = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE);
      tickVal = NormalizeDouble(tickVal, Digits());
      
      if (tickVal > 0.0) {
      
         break;
      
      } else {
      
         Print("> Fehler für Symbol " + _Symbol + ", tickValue = 0.0, versuche es noch einmal...");
         Sleep(1000);
         Print("> Fehler bei Holen von TickValue: " + IntegerToString(GetLastError()));
      
      }
   

   }
The error appeared on two machines at different times.
 
lukasp1 #:

Hi, thanks for your tip.


After reloading the EA, the correct tickValue has been read and the order has been created.


I've appended some debug information today in hoping to get more error details next time:


The error appeared on two machines at different times.
May I ask what symbol you are having the issue on?

And here:



It is more or less occasionally that your code is working.

 
Dominik Christian Egert #:
May I ask what symbol you are having the issue on?

And here:



It is more or less occasionally that your code is working.


Hi Dominik, thx for you advise. I'll take your function for last solution :-)


Why do you think my code works more or less occasionally?


regards

Lukas

 

I've taken a look at user interfaces value, here's the problem (AUDJPY):


TickValue is only shown in Strategy Testers Symbolinformation.


Update: After opening the symbol information window again, TickValue has been calculated. Why does MT5 need a second try here? Perhaps one step to solution...


Update: same for AUDSGD


Update: same problem loop after MT restart: value shown at first: 0.0000.., second try: 0.7...real TickValue.

Files:
prob.png  21 kb
 
lukasp1 #:

I've taken a look at user interfaces value, here's the problem (AUDJPY):


TickValue is only shown in Strategy Testers Symbolinformation.


Update: After opening the symbol information window again, TickValue has been calculated. Why does MT5 need a second try here? Perhaps one step to solution...


Update: same for AUDSGD

Is has been pointed out in the thread I've linked, tick_value is only reliable, if it is required for the symbols profit calculations. 

Brokers will provide different values, sometimes in base/profit-currency of the symbol, sometimes in account currency. If given in account-currency, the server will take a moment to compute the value, therefore, it might be delayed in delivery. - As said, as long as the value is not required for the profit calculations, its not reliable. - Thats why I said, it will work occasionally.

 
Dominik Christian Egert #:

Is has been pointed out in the thread I've linked, tick_value is only reliable, if it is required for the symbols profit calculations. 

Brokers will provide different values, sometimes in base/profit-currency of the symbol, sometimes in account currency. If given in account-currency, the server will take a moment to compute the value, therefore, it might be delayed in delivery. - As said, as long as the value is not required for the profit calculations, its not reliable. - Thats why I said, it will work occasionally.

Hi Dominik,

thanks for your solution, I like it.


Once I use this workaround (tested):

Periodically call SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE) , eg. every PERIOD_H1 candle.

Then there's an existing value a long time BEFORE you need it for making orders. Not just one code line and some seconds before OrderSend().

Also I've read  https://www.mql5.com/en/forum/425413 completely - but I don't understand what you mean with 'profit calculations'. Do you mean using SYMBOL_TRADE_TICK_VALUE_PROFIT doesn't produce the empty value error in contrast? Or did you just want to say, there is no need to use broker's precomputed value of  SYMBOL_TRADE_TICK_VALUE just for calculating the stopp loss?

Symbol Point Value - Can you tell me how MT5 calculates point value using the SYMBOL_POINTenum?
Symbol Point Value - Can you tell me how MT5 calculates point value using the SYMBOL_POINTenum?
  • 2022.05.18
  • www.mql5.com
There is also tick size and tick value. I will change the code to use tick size and value. In essence, make sure that your price quotes, are properly aligned to the tick size (see following examples). Usdzar where spread is over 500 points), and metals
 
Hmm...

I am not sure, we are on the same page.

Trade tick value is a property taken from the symbol. If this value is not required by the calculation defined in the documentation as shown here:


And specifically in this property:

ENUM_SYMBOL_CALC_MODE


In the table, the right most column will show the formulas for profit calculations.


If tick value is not refered to there, then it is unreliable and can be given in any currency, base/profit or account currency.


 
Dominik Christian Egert #:
Hmm...

I am not sure, we are on the same page.

Trade tick value is a property taken from the symbol. If this value is not required by the calculation defined in the documentation as shown here:


And specifically in this property:

ENUM_SYMBOL_CALC_MODE


In the table, the right most column will show the formulas for profit calculations.


If tick value is not refered to there, then it is unreliable and can be given in any currency, base/profit or account currency.


Hi Dominik,


ok, now I know what you mean, thank you very much.

Personally I think there shouldn't be any empty return values because of network delays (async). That seems to be not ok in my opinion.

But now we know some good workarounds :-)

regards

Lukas

 
Philippe Pauleau #: Sometimes first call to SYMBOL_TRADE_TICK_VALUE returns 0 but the following calls are returning correct values. How do you calculate TickValue to replace unreliable  SYMBOL_TRADE_TICK_VALUE ?

As explained by @Dominik Christian Egert in one of his previous posts (see below), the Tick Value is only required if the profit calculation method requires it. If it does not, then there is no need to obtain the Tick Value and it maybe unreliable.

Also, you should only read the Tick Value, after the first tick has arrived. Prior to that the connection with the trade server may not have yet established properly for the required symbol data to have been fully downloaded.

Forum on trading, automated trading systems and testing trading strategies

SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE) sometimes zero

Dominik Christian Egert, 2022.08.09 21:58

Hmm...

I am not sure, we are on the same page.

Trade tick value is a property taken from the symbol. If this value is not required by the calculation defined in the documentation as shown here:


And specifically in this property:

ENUM_SYMBOL_CALC_MODE


In the table, the right most column will show the formulas for profit calculations.


If tick value is not refered to there, then it is unreliable and can be given in any currency, base/profit or account currency.



The ENUM_SYMBOL_CALC_MODE enumeration is used for obtaining information about how the margin requirements for a symbol are calculated.

ENUM_SYMBOL_CALC_MODE

Identifier

Description

Formula

SYMBOL_CALC_MODE_FOREX

Forex mode - calculation of profit and margin for Forex

Margin:  Lots * Contract_Size / Leverage * Margin_Rate

Profit:   (close_price - open_price) * Contract_Size*Lots

SYMBOL_CALC_MODE_FOREX_NO_LEVERAGE

Forex No Leverage mode – calculation of profit and margin for Forex symbols without taking into account the leverage

Margin:  Lots * Contract_Size * Margin_Rate

Profit:   (close_price - open_price) * Contract_Size * Lots

SYMBOL_CALC_MODE_FUTURES

Futures mode - calculation of margin and profit for futures

Margin: Lots * InitialMargin * Margin_Rate

Profit:  (close_price - open_price) * TickPrice / TickSize*Lots

SYMBOL_CALC_MODE_CFD

CFD mode - calculation of margin and profit for CFD

Margin: Lots * ContractSize * MarketPrice * Margin_Rate

Profit:  (close_price - open_price) * Contract_Size * Lots

SYMBOL_CALC_MODE_CFDINDEX

CFD index mode - calculation of margin and profit for CFD by indexes

Margin: (Lots * ContractSize * MarketPrice) * TickPrice / TickSize * Margin_Rate

Profit:  (close_price - open_price) * Contract_Size * Lots

SYMBOL_CALC_MODE_CFDLEVERAGE

CFD Leverage mode - calculation of margin and profit for CFD at leverage trading

Margin: (Lots * ContractSize * MarketPrice) / Leverage * Margin_Rate

Profit:  (close_price-open_price) * Contract_Size * Lots

SYMBOL_CALC_MODE_EXCH_STOCKS

Exchange mode – calculation of margin and profit for trading securities on a stock exchange

Margin: Lots * ContractSize * LastPrice * Margin_Rate

Profit:  (close_price - open_price) * Contract_Size * Lots

SYMBOL_CALC_MODE_EXCH_FUTURES

Futures mode –  calculation of margin and profit for trading futures contracts on a stock exchange

Margin: Lots * InitialMargin * Margin_Rate or Lots * MaintenanceMargin * Margin_Rate

Profit:  (close_price - open_price) * Lots * TickPrice / TickSize

SYMBOL_CALC_MODE_EXCH_FUTURES_FORTS

FORTS Futures mode –  calculation of margin and profit for trading futures contracts on FORTS. The margin may be reduced by the amount of MarginDiscount deviation according to the following rules:

1. If the price of a long position (buy order) is less than the estimated price, MarginDiscount = Lots*((PriceSettle-PriceOrder)*TickPrice/TickSize)

2. If the price of a short position (sell order) exceeds the estimated price, MarginDiscount = Lots*((PriceOrder-PriceSettle)*TickPrice/TickSize)

where:

    • PriceSettle – estimated (clearing) price of the previous session;
    • PriceOrder – average weighted position price or open price set in the order (request);
    • TickPrice – tick price (cost of the price change by one point)
    • TickSize – tick size (minimum price change step)

Margin: Lots * InitialMargin * Margin_Rate or Lots * MaintenanceMargin * Margin_Rate * Margin_Rate

Profit:  (close_price - open_price) * Lots * TickPrice / TickSize

SYMBOL_CALC_MODE_EXCH_BONDS

Exchange Bonds mode – calculation of margin and profit for trading bonds on a stock exchange

Margin: Lots * ContractSize * FaceValue * open_price * /100

Profit:  Lots * close_price * FaceValue * Contract_Size  + AccruedInterest * Lots * ContractSize

SYMBOL_CALC_MODE_EXCH_STOCKS_MOEX

Exchange MOEX Stocks mode – calculation of margin and profit for trading securities on MOEX

Margin: Lots * ContractSize * LastPrice * Margin_Rate

Profit:  (close_price - open_price) * Contract_Size * Lots

SYMBOL_CALC_MODE_EXCH_BONDS_MOEX

Exchange MOEX Bonds mode – calculation of margin and profit for trading bonds on MOEX

Margin: Lots * ContractSize * FaceValue * open_price * /100

Profit:  Lots * close_price * FaceValue * Contract_Size  + AccruedInterest * Lots * ContractSize

SYMBOL_CALC_MODE_SERV_COLLATERAL

Collateral mode - a symbol is used as a non-tradable asset on a trading account. The market value of an open position is calculated based on the volume, current market price, contract size and liquidity ratio. The value is included into Assets, which are added to Equity. Open positions of such symbols increase the Free Margin amount and are used as additional margin (collateral) for open positions of tradable instruments.

Margin: no

Profit:  no

Market Value: Lots*ContractSize*MarketPrice*LiqudityRate

Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Symbol Properties - Environment State - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Reason: