Lot volume given by risk formula exceeds free margin

 
@page { size: 8.27in 11.69in; margin: 0.79in } p { margin-bottom: 0.1in; line-height: 100%; background: transparent } code { font-family: "Liberation Mono", monospace }

Hello

I know that this topic has been discussed many times and many great answers have been posted, but there is still something not clear for me.

I would like to trade with fix risk exposure (1% of account balance). Here is an example:

Account balance: $1,000

EUR/USD: 1.1582

Stop Loss: 1.1579

double price = 1.1582;

double SL = 1.1579;

double riskPercent = 0.01;

double risk = account.Balance()*riskPercent;

// Using the formula: amount at risk = pips at risk * pip value * lots traded

double pip_value = 10;// 1 pip equals $10 for lots

double deltaValuePerLot = 10000;// to convert market price difference into pips

double lotVolume = NormalizeLots(risk/(MathAbs(price-SL)*deltaValuePerLot*pip_value), symbol);


Here, the result would be: lotVolume = 0.33

OK, but then, how am I supposed to buy 3 mini lots?

This would be 3*10,000*1.1582 = $34,746 while I only have $1,000 on my account.

All documentation I could read stop here in terms of risk management. But my broker tells me that I do not have enough free margin for this order , which seems logical…


So my questions are:

- I s there any mistake in my reasoning, and if so, please help me correct it?

- I f there is no mistake, how can I risk 1% of my balance within correct margin? Using leverage?

- If I need to u s e leverage, please, what is then the risk formula to apply? Where should I take into account the leverage level?


@page { size: 8.27in 11.69in; margin: 0.79in } p { margin-bottom: 0.1in; line-height: 100%; background: transparent } code { font-family: "Liberation Mono", monospace }

Thanks a lot, I am stuck with this issue for 1+ month. Any help is much appreciated!

 
davipowell: - I s there any mistake in my reasoning, and if so, please help me correct it?
double deltaValuePerLot = 10000;// to convert market price difference into pips

Yes, hard coded bogus conversion factor.

Risk depends on your initial stop loss, lot size, and the value of the symbol. It does not depend on margin and leverage. No SL means you have infinite risk. Never risk more than a small percentage of your trading funds, certainly less than 2% per trade, 6% total.

  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)
              Is there an universal solution for Tick value? - Currency Pairs - General - MQL5 programming forum (2018)
              Lot value calculation off by a factor of 100 - MQL5 programming forum (2019)

  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.

 
@page { size: 8.27in 11.69in; margin: 0.79in } pre { font-family: "Liberation Mono", monospace; font-size: 10pt; background: transparent } p { margin-bottom: 0.1in; line-height: 100%; background: transparent } code { font-family: "Liberation Mono", monospace }

Hello William Roeder

First, I must say that I really appreciate your expertise. Your answers have been many times helpful to me!

Taking into account your comments, here is my new version:

double DeltaValuePerLot(string pair="")
{
 /* All credit goes to William Roeder */ 
if (pair == "") pair = Symbol(); 
return( SymbolInfoDouble(pair, SYMBOL_TRADE_TICK_VALUE) / 
SymbolInfoDouble(pair, SYMBOL_TRADE_TICK_SIZE) ); // Not Point. 
} 
double price = 1.1582; 
double SL = 1.1579; 
double riskPercent = 0.01; 
double risk = account.Balance()*riskPercent; 
// Using the formula: amount at risk = pips at risk * pip value * lots traded 
double lotVolume = NormalizeLots(risk/(MathAbs(price-SL)*DeltaValuePerLot() + commissionPerLot), symbol);

I am using your recommended functions. In my case (account in Dollar and trading EUR/USD), DeltaValuePerLot() returns 99,999.9999

I am not sure whether this is an expected behavior, because that is different to $10/pip, however this seems more logical to me.

Please, I am still confused regarding the following points:

  1. Let’s assume the correct value returned by DeltaValuePerLot () would have been $10/pip. In this case, lotVolume = $10/(0.0003*$10 + commissionPerLot) = 3,333.33 lots. I am not sure this value makes sense. What about adding my previous “bogus” conversion factor? Or is there any other mistake in my reasoning?
  2. Regardi n g your l ast example, please, I am still not sure how to have enough free margin. Let’s assume your account has $10,000, how would you buy 0.1 Lots, which is $10,000* 1.1582 = $11,582? It seems we have to use leverage even for that small risk?

Thanks a lot for your time and your expertise.

 

In any case tick value is the  quote currency rate to the account curency rate.

For instance  tick value of  UK 100 FTSE for an account in Euro is : GBPEUR . or, as GBPEUR doesn't exist,  1 / EURGBP

It could happen that more than one convversion are needed, and tick value is not historical so it is wrong to apply that formula  to past trades in backtest.

We are better off computing tick value  thant relying on brokers to set it right.

Reason: