Mathematical curiosity in lot size calculation

 

Imagine the simple problem, I have £10,000 and I am only willing to lose 1% of that with the next trade. The next trade is on EURNZD, an XXX/NZD pair. If my stop loss is 100 pips, what is my lot size?

I know the answer since I have calculated in the code below. But what I am wondering is why I have a *0.1 constant, the underlined part. I've always accepted it is there to ensure my lot size is not out by an order of magnitude, but why exactly is it there? Is it just to do with the way I have inefficiently calculated lot sizes?

double GUrate=MarketInfo("GBPUSD",MODE_BID);
double NUrate=MarketInfo("NZDUSD",MODE_BID);

double GBPbalance=AccountBalance(); //e.g. 10,000
double USDbalance=(GUrate*GBPbalance);
   
string CurrentSymbol=Symbol();

double ENrisk=0.01; //1%
double ENCurrentSL=100; //in pips

double ENlotsize=(((ENrisk*USDbalance)/ENCurrentSL)*0.1*(1/NUrate));

 
eempc:

Imagine the simple problem, I have £10,000 and I am only willing to lose 1% of that with the next trade. The next trade is on EURNZD, an XXX/NZD pair. If my stop loss is 100 pips, what is my lot size?

I know the answer since I have calculated in the code below. 

I suspect you don't know the answer at all as you have introduced a *  0.1 into your code without knowing why.  You have a GBP account and are trading EUR NZD  so why are you using the GBPUSD rate ?

Perhaps you could explain the logic behind your code, step by step ? 

 
eempc:

Imagine the simple problem, I have £10,000 and I am only willing to lose 1% of that with the next trade. The next trade is on EURNZD, an XXX/NZD pair. If my stop loss is 100 pips, what is my lot size?

I know the answer since I have calculated in the code below. But what I am wondering is why I have a *0.1 constant, the underlined part. I've always accepted it is there to ensure my lot size is not out by an order of magnitude, but why exactly is it there? Is it just to do with the way I have inefficiently calculated lot sizes?


I think it might just be a method of just changing units from $ values to lot values...
 
RaptorUK:

I suspect you don't know the answer at all as you have introduced a *  0.1 into your code without knowing why.  You have a GBP account and are trading EUR NZD  so why are you using the GBPUSD rate ?

Perhaps you could explain the logic behind your code, step by step ? 

I am going to simplify to USD denominated account. I risk 1% on $10,000 with a 100 pip SL and playing EURUSD now.

First I calculate the absolute amount that I want to lose:

risk*USDbalance, i.e. 0.01*$10,000 = $100

Then I divide that $100 by the SL of 100 to get the value per pip:

$100 / 100 = $1 per pip

But I know that to obtain $1 per pip, I need to enter 0.10 into the MT4 order execution screen. Entering 1.00 would result in $10 per pip! This was determined empirically though.

 
eempc:

I am going to simplify to USD denominated account. I risk 1% on $10,000 with a 100 pip SL and playing EURUSD now.

First I calculate the absolute amount that I want to lose:

risk*USDbalance, i.e. 0.01*$10,000 = $100

Then I divide that $100 by the SL of 100 to get the value per pip:

$100 / 100 = $1 per pip

But I know that to obtain $1 per pip, I need to enter 0.10 into the MT4 order execution screen. Entering 1.00 would result in $10 per pip! This was determined empirically though.

Isn't it $1 per point and $10 per pip ?  a pip is the 4th/2nd digit,  point is the 5th/3rd digit on Forex
 
eempc:

I am going to simplify to USD denominated account. I risk 1% on $10,000 with a 100 pip SL and playing EURUSD now.

First I calculate the absolute amount that I want to lose:

risk*USDbalance, i.e. 0.01*$10,000 = $100

Then I divide that $100 by the SL of 100 to get the value per pip:

$100 / 100 = $1 per pip

But I know that to obtain $1 per pip, I need to enter 0.10 into the MT4 order execution screen. Entering 1.00 would result in $10 per pip! This was determined empirically though.


It is worth noting you know what you are doing ;-)

What is a pip, what is a lot ? A pip is a variation of 0.0001 of the quote. If you trade a lot, you have 100.000 unit of base currency. So a variation of 0.0001 on 100.000 units give you a difference of 10.

Example, EURUSD, Buy 1 lot, quote 1.3073 : 100 000€ -> 130 730$

New quote 1.3072 : you have 100 000€  -> 130 720$, then you have lost 10$

LOTS = risk (%) * Balance / (SL (pips) * pipvalue (1 lot))   

This is origin of your 0.1. You have now to convert profit currency ($ in example) of the symbol you trade into your account currency.

Edit : For symbol with JPY, a pip is 0.01.

 

Yeah I work in pips (4th decimal point), not pipettes (5th decimal point).

Yes I see it now: (risk * balance) / (SL * pipvalue of 10 per lot) is the same as ((risk*balance) / SL) *0.1

I try to convert everything to USD first (maybe not the most efficient way) but it gets the job done.

Okay, the 0.1 mystery is solved. Cheers!

 

It is NOT $1 or $10 per pip. It depends on the pair AND your account currency. If you trade xxxUSD on a USD account, yes. If you trade EURUSD on a EUR then it's 0.77EUR per (1/ EURUSD rate.) If you trade GBPJPY on a USD its a multiple of several rates.


risk want = risk * balance(account Currency)

risk order per lot = ( orderOpenPrice - sl )*DIR * value point(in account Currency)

lot = risk want / risk order per lot;

adjust to brokers limits

No multiple needed.

From my code

double   DeltaValuePerLot(string pair=""){
   //{Value in account currency of a Point of Symbol.
   // In tester I had a sale: open=1.35883 close=1.35736 (0.0147)
   // gain$=97.32/6.62 lots/147 points=$0.10/point    or $1.00/pip.
   // IBFX demo/mini       EURUSD TICKVALUE=0.1 MAXLOT=50 LOTSIZE=10,000
   // IBFX demo/standard   EURUSD TICKVALUE=1.0 MAXLOT=50 LOTSIZE=100,000
   //                      $1.00/point    or $10.0/pip.
   //
   // https://www.mql5.com/en/forum/127584 CB: MODE_TICKSIZE will usually return the same
   // value as MODE_POINT (or Point for the current symbol), however, an example
   // of where to use MODE_TICKSIZE would be as part of a ratio with
   // MODE_TICKVALUE when performing money management calculations which need to
   // take account of the pair and the account currency. The reason I use this
   // ratio is that although TV and TS may constantly be returned as something
   // like 7.00 and 0.0001 respectively, I've seen this (intermittently) change
   // to 14.00 and 0.0002 respectively (just example tick values to illustrate).
   // https://www.mql5.com/en/forum/135345 zzuegg reports for non-currency DE30:
   // MarketInfo(symbol.chart,MODE_TICKSIZE) returns 0.5
   // MarketInfo(symbol.chart,MODE_DIGITS)   return 1
   // Point    = 0.1
   // Prices to open must be a multiple of ticksize
   //}
   if(pair == "") pair = Symbol();
   return( MarketInfo(pair, MODE_TICKVALUE)
         / MarketInfo(pair, MODE_TICKSIZE) ); // Not Point.
}
Reason: