wrong value for SYMBOL_TRADE_TICK_VALUE - page 4

 
jossnet #:
@Miguel Angel Vico Alba  :thanks for the snippet. i'll give it a try immidiatly.
@Fernando Carreiro  : I apologies for this. I usually try to read a tons of posts searching for a matching of my  need with posts and not to burden you in the group with work. i could not immagine of broken config.  In any case thank for your patience.
 

Don't worry, your problem (although already much discussed on the forum) is entirely laudable. I myself have suffered from it for a long time.

 
jossnet #: @Miguel Angel Vico Alba  :thanks for the snippet. i'll give it a try immidiatly. @Fernando Carreiro  : I apologies for this. I usually try to read a tons of posts searching for a matching of my  need with posts and not to burden you in the group with work. i could not immagine of broken config.  In any case thank for your patience.

For my part, you are welcome!

When and if you get an answer from your broker, please let us know their response here on this thread.

 

ok ,

i tried to test the code Miguel posted , and these are my results after i changer two lines of code  :

double CalculateTickValue(const string pSymbol)
  {
   double TickSize = SymbolInfoDouble(pSymbol, SYMBOL_TRADE_TICK_SIZE);
   double LotSize = SymbolInfoDouble(pSymbol, SYMBOL_TRADE_CONTRACT_SIZE);
   double TickValue = LotSize * TickSize;
   double eurValue = 0, newTickValue, bid;

   const string prof = SymbolInfoString(pSymbol, SYMBOL_CURRENCY_PROFIT);               // second pair part ( USD)
   const string acc  = AccountInfoString(ACCOUNT_CURRENCY);                                                     // primary pair part
//--- converting into deposit currency.
   if(prof != acc)
        {
                eurValue = GetCrossRate(prof, acc);  		// added line
                bid = SymbolInfoDouble(pSymbol, SYMBOL_BID);	// added line 
                newTickValue = eurValue / bid;			// added line 
                TickValue *=  eurValue;
        }

   return TickValue;
  }

for my point of view a corret tickvalue  is about : 0.000465729646487196  for a bid price XAU of 1976.88

for   my point of view   the call to   GetCrossRate(prof, acc); is enough  to return  0.920691623547609028  

I do not undestand the original 
TickValue *= GetCrossRate(prof, acc); because it give  0.0920691623547609028.
the correct value for my understanding should be   0.000465729646487196  isn't it ??


the second case from  Trinh Dat is hard to read for me because :

for a price of 1977.849999999999909051 it return 0.089999999999999997 ....what does it mean ??

could you check what are the correct value  0.000465729646487196  or  0.089999999999999997 ??

also i read this post try to clear my understanding. 
https://www.mql5.com/en/forum/439319 

thanks 




Trinh Dat
Trinh Dat
  • 2023.02.26
  • www.mql5.com
Trader's profile
 
jossnet #:

This code is only part of a much larger code and only serves as an example. 

Here is an example from CodeBase by the same author of the topic you posted and the code I posted.

Check carefully the file Functions.mqh

https://www.mql5.com/en/code/28029

Forex Calculators
Forex Calculators
  • www.mql5.com
Margin Calculator, Point Value Calculator, Position Size Calculator, Profit Calculator and Swap Calculator.
 
jossnet #: for my point of view a corret tickvalue  is about : 0.000465729646487196  for a bid price XAU of 1976.88.

for   my point of view   the call to   GetCrossRate(prof, acc); is enough  to return  0.920691623547609028
I do not undestand the original 
TickValue *= GetCrossRate(prof, acc); because it give  0.0920691623547609028.
the correct value for my understanding should be   0.000465729646487196  isn't it ??

The correct value is 0.920691623547609028 (depending on tick size). It is not 0.000465729646487196!

Tick value does not depend on the price of XAUUSD. The tick value for XAUUSD is a constant $1 USD (depends on tick size) for any and all prices of XUAUSD.

When it is converted to EUR it then varies depending of the price of EURUSD, but it is still totally independent of XAUUSD price.

 

Ok @Fernando Carreiro :  sorry for delay ...I tried  to go to the end and I would like to have your opinion , so :

first : applying  the formula above 

 CalculateTickValue(
"XAUUSD" )

I received the value of  0.0920691623547609028  but i was expecting  0.920691623547609028  -> 0.9 and not 0.09  wich one is correct?.

also , in That function I do not understand  -> TickValue   *= GetCrossRate(prof, accn);   //  TickValue  *=    ... while i was thinking  ... TickValue   = 


second : if I apply this formula for "XAUUSD"  :
  
lot = AccountBalance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot)  
https://www.mql5.com/en/forum/444637

double CalculateLotSize(double tickSize, double riskPercent, double stopLoss) // tickSize= 0.01 riskPercent=1.00 stopLoss= 1928.655
{
        string symbol = ChartSymbol(ID);
   double minlot  = SymbolInfoDouble(symbol,SYMBOL_VOLUME_MIN);
        double maxlot  = SymbolInfoDouble(symbol,SYMBOL_VOLUME_MAX);   
   double LotStep = SymbolInfoDouble(symbol,SYMBOL_VOLUME_STEP);
   double TickValue = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_VALUE ); // not use for xau
   double balance = AccountInfoDouble(ACCOUNT_BALANCE);
   
   TickValue = CalculateTickValue(symbol);                      // suppose it return 0.92035267914664903
   double deltaPerLot =  TickValue / tickSize;                  // 0.9203522679 / 0.01 = 92.0352679
   
   double riskAmount = balance * riskPercent / 100;                     // (100000 *0.01) =990
   double pointsOfStopLoss = MathAbs(stopLoss - _Ask);                  // 1928.655 -1929.660 = 1.005
   double lotSize = riskAmount / (pointsOfStopLoss * deltaPerLot );     // 990.9378 / 1.005*92.0352679  // 990.9378/ 92.4954442 = 10.71
   
   lotSize = MathRound(lotSize/LotStep) * LotStep;
   if (lotSize < minlot) lotSize = minlot;    // or 0
   if (lotSize > maxlot) lotSize = maxlot; 
      
   return lotSize;
}

Is 10.71 correct ??  I think no.  
then .. would you give me a sight and show me  where I'am wrong ? 
then .. can I apply the same formula for pair like "EURUSD" and "XAUUSD" ??

thank



 
@Fernando Carreiro  ;  Hi Fernando ,

I have to tank you very much because trying and trying again i found the solution by my own ( I hope )  but thanks to your suggestions and examples, specifically 2 articles

https://www.mql5.com/en/forum/441959/page7
Balance: €1000
Risk (1%): €10
Stop-loss: 1000 ticks
Symbol: EURUSD
Current price: 1.05451

Current tick value: $1 = €0.948307744829352
Risk for 1 Lot = 1000 ticks x tick-value = €948.307744829352
Volume = €10 / €948.307744829352 = 0.01054510.01 (rounded)
in this snippet it turns out 2 things , but before we must state that :

lot = maximum amount we are willing to risk / maximum amount we are willing to lose


1. maximum amount we are willing to risk  = ( balance * 0.01)....
2. maximum amount we are willing to lose 
for calculate this value we have more than one way  but substantially you have to refer to the concept of stoploss.
but is important to note that the stoploss value must be expressed in TICKS  and  multiplied for a value of a single TICK (in account currency ).  
so  for calculate the  stoploss values  there are different ways : 1.  specify a stoploss in pips and multiply by 10 because one pip is = to 10 points and then divide for ticksize . this example is clear
https://www.mql5.com/en/forum/373815
If the Symbol is EURUSD, then [Tick Value] = $1.00, [Tick Size] = 0.00001 and [T/P Size] = 80 pips = 0.00800, [Reward] = $500.00

Volume = ($500 * 0.00001) / (0.00800 * $1) = 0.005 / 0.008 = 0.625 Lots = 0.63 Lots

   in this example  0.008 TICKS = has been calculate with 80pips *10 point per tick / 0.00001  ( ticksize for EURUSD) 

2. specify a stoploss directly in tick as showed in above first snippet  like  Stop-loss : 1000 ticks

3.  specify a stoploss with 2 prices ( openprice - stoplossprice )  and divide for  ticksize  ( example for "XAUUSD"  (1928.960 -1928.655)/ ticksize  

After you have the number of ticks for the stoploss you have to multiply number of ticks for a tickvalue in account currency . With this last step you have to be aware because the tickvalue MUST be the exchange of the profit currency to the account currency. 
last thing to be aware is the contracts  size of your broker for every Pairs, usefull to check if your lotsize is correct.
example for "XAUUSD" pair with ticksize =0.01 and tickvalue =0.091764166093140628 with EUR value of 1.08825
lotsize = (500000 * 0.01)  / (( 1928.960 -1928.655) /ticksize ) * tickvalue ) 
   = 5000 / ( 30.5 *  0.091764166093140628 ) 
   = 5000 / 2.79880707 = 1786.47541  with a broker contract size of 10 for the "XAUUSD".

final lotsize  = MathRound( lotsize  /LotStep) * LotStep;
if (lotSize < minlot) lotSize = minlot; 
 if (lotSize > maxlot) lotSize = maxlot; 

example for "EURUSD" pair with ticksize =0.00001 and tickvalue =0.091764166093140628 with EUR value of 1.08825
lotsize =  (100000 * 0.01)  / (1.06520-1.06320)/ ticksize  ) * TickValue
   =  1000 / ( 200 *  0.091764166093140628 )
   =  1000 / 18.3528332 = 54.487501   with a broker contract size of 10000 for the "EURUSD"

I also attack a picture . see in bottom.

I'm probably missing something and some calculations aren't very precise but I wanted to give the sense of the general calculation. could you please check all this work. I hope, if it's correct, it will be of some utility for someone here in forum. thanks Fernando to you and to all group.







Files:
CalcLotsize.png  32 kb
 
jossnet #@Fernando Carreiro  ;  Hi Fernando

I did not go over all your steps, but I have to ask if maybe you are not over complicating things. Yes the following is how you would calculating things ...

Forum on trading, automated trading systems and testing trading strategies

How to calculate take profit from currency

Fernando Carreiro, 2022.09.05 17:00

These are all the same equation written in different ways ...

[Volume]      = [Money Value] * [Tick Size] / ( [Tick Value] * [Stop Size] )
[Stop Size]   = [Money Value] * [Tick Size] / ( [Tick Value] * [Volume]    )
[Money Value] = [Volume]      * [Stop Size] * [Tick Value]   / [Tick Size]

[Volume] in lots
[Stop Size] in quote price change
[Money Value] in account currency

However, have you tried using the built-in functions that MQL5 provides, namely OrderCalcProfit, and see if it gives the correct results before attempting to code your own calculations?

Forum on trading, automated trading systems and testing trading strategies

SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE) sometimes zero

Fernando Carreiro, 2022.08.23 16:51

Instead of using the Tick Value directly, consider using the function OrderCalcProfit, because it will apply the correct profit calculation method depending on the CALC_MODE for that symbol.

Forum on trading, automated trading systems and testing trading strategies

SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE) sometimes zero

Fernando Carreiro, 2022.08.23 17:41

You can! These are the steps I take. I supply the function with a lot size equal to the “Max Lot Size” allowed for the symbol in question, then calculate the ratio needed to achieve the fractional risk that I wish to apply, to get the correct volume for the order. I then align that with the “Lot Step” and finally check it against both the maximum and minimum allowed lots for the symbol.

The reason I use the “maximum” lots instead of just “1.0” lots as a reference value is because there is no guarantee that the value of 1.0 is within the minimum and maximum values allowed. Given that using 1.0, or the maximum, gives equivalent results anyway (by using the ratio method), I choose to use the “max lots” as the reference point which also offers the most precision for the calculation.

Something like this ...

// This code will not compile. It is only a example reference

if( OrderCalcProfit( eOrderType, _Symbol, dbLotsMax, dbPriceOpen, dbPriceStopLoss, dbProfit ) )
{
   dbOrderLots = fmin( fmax( round( dbRiskMax * dbLotsMax / ( -dbProfit * dbLotsStep ) )
               * dbLotsStep, dbLotsMin ), dbLotsMax ); 
      
   // the rest of the code ...
};
Documentation on MQL5: Trade Functions / OrderCalcProfit
Documentation on MQL5: Trade Functions / OrderCalcProfit
  • www.mql5.com
OrderCalcProfit - Trade Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

SYMBOL_TRADE_TICK_VALUE is a built-in MQL variable that represents the minimum price change of a trading instrument. The value of SYMBOL_TRADE_TICK_VALUE is dependent on the currency pair and the account currency.

If you believe that the value of SYMBOL_TRADE_TICK_VALUE is incorrect, you may want to double-check that you are using the correct symbol and account currency in your code. You can also check the symbol specifications in your trading platform or on the broker's website to confirm the tick value. 

If you continue to have issues with SYMBOL_TRADE_TICK_VALUE , you can try contacting the MQL community or the support team of your trading platform or broker for further assistance. They may be able to provide more specific guidance on how to resolve the issue.

 
@Ayesha Ayoub #: SYMBOL_TRADE_TICK_VALUE is a built-in MQL variable that represents the minimum price change of a trading instrument. The value of SYMBOL_TRADE_TICK_VALUE is dependent on the currency pair and the account currency. If you believe that the value of SYMBOL_TRADE_TICK_VALUE is incorrect, you may want to double-check that you are using the correct symbol and account currency in your code. You can also check the symbol specifications in your trading platform or on the broker's website to confirm the tick value. f you continue to have issues with SYMBOL_TRADE_TICK_VALUE , you can try contacting the MQL community or the support team of your trading platform or broker for further assistance. They may be able to provide more specific guidance on how to resolve the issue.

It seems that you did not read this thread from start to finish. All of that has already been addressed, analysed, issue identified, the broker contacted and possible solutions have been proposed. Now things have evolved beyond that initial issue onto another related topic of the discussion.