confusion with TICK_VALUE and TICK_SIZE

 

I have a problem understanding why this calculation gives back a wrong result.

relativeSL = NormalizeDouble(moneyToRisk/tickvalue*ticksize, digits);

I thought the tick value should be the amount a tick is worth (in the accounts currency), but instead it's 100 times more.

What is it that I don't understand? Or is it just the Broker giving back the wrong tick value? (I tried it on two different Brokers)


To understand it better I printed the relevant varibles with the following command:

Print("availableMoney = "+DoubleToString(availableMoney,2)
                                                +", percentage = "+percentage
                                                +", moneyToRisk = "+DoubleToString(NormalizeDouble(moneyToRisk,3),3)
                                                +", relativeSL = "+DoubleToString(NormalizeDouble(relativeSL,6),digits)
                                                +", tickvalue = "+DoubleToString(NormalizeDouble(tickvalue,6),7)
                                                +", ticksize = "+DoubleToString(NormalizeDouble(ticksize,6),digits)
                                                +", pointValue = "+DoubleToString(NormalizeDouble(pointValue,6),digits)
                                                +", digits = "+digits);

The Output is:

availableMoney = 777.29, percentage = 1.0, moneyToRisk = 7.773, relativeSL = 0.00008, tickvalue = 1.0048840, ticksize = 0.00001, pointValue = 0.00001, digits = 5

While the calculation itself is correct, the relativeSL should be about 0.00773 to fit to the 7.773 USD shown in the moneyToRisk.


[edit: how can I move this thread to the EA section? Just realised that I'm in the general section]

 
In code (MT4): Risk depends on your initial stop loss, lot size, and the value of the pair. It does not depend on margin and leverage.
  1. You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
  2. AccountBalance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the spread, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
  3. Do NOT use TickValue by itself - DeltaPerLot and verify that MODE_TICKVALUE is returning a value in your deposit currency, as promised by the documentation, or whether it is returning a value in the instrument's base currency.
              MODE_TICKVALUE is not reliable on non-fx instruments with many brokers - MQL4 programming forum 2017.10.10
              Lot value calculation off by a factor of 100 - MQL5 programming forum 2019.07.19
  4. You must normalize lots properly and check against min and max.
  5. You must also check FreeMargin to avoid stop out

Most pairs are worth about $10 per PIP. A $5 risk with a (very small) 5 PIP SL is $5/$10/5 or 0.1 Lots maximum.

 
Jorma Spitz:

I have a problem understanding why this calculation gives back a wrong result.

I thought the tick value should be the amount a tick is worth (in the accounts currency), but instead it's 100 times more.

What is it that I don't understand? Or is it just the Broker giving back the wrong tick value? (I tried it on two different Brokers)


To understand it better I printed the relevant varibles with the following command:

The Output is:

While the calculation itself is correct, the relativeSL should be about 0.00773 to fit to the 7.773 USD shown in the moneyToRisk.


[edit: how can I move this thread to the EA section? Just realised that I'm in the general section]

And where is the lot size in your calculation ?

The calculation are correct for 1 standard lot. If ticksize is 0.00001 that gives well around 1 USD for tickvalue. So for 7.773 USD to risk, it's a move of 0.00007773, rounded to 0.00008.

 

Thank you for your fast response. I guess it's really a problem of getting the wrong tickvalue from the broker.

I actually just try to make a simple EA that automatically sets SL based on a predefined balance(or equity)-percentage for manually opened positions. So OrderLots and OrderOpenPrice are predefined and spread is irrelevant since the order is already active.

And I just have the impression that I should study the DeltaPerLot tomorrow to understand this part better. :)

 
Alain Verleyen:

And where is the lot size in your calculation ?

Oh my gosh! You're right! That's it!

A huge thank you for your observation!! You just saved my day!! :D