# Formula to calculate Lot quantity and lot size

Hi im making my own "indicator" to calculate lot quantity so i can handle fast trades witouth using calculator.

An example, i got following:

Dax30

Tick value: 0.1

Tick size: 0.1

Stop loss pip: 1000 (11990.00)

Risk percentage: 3%

Balance: 250€

Stop loss max risk: 7,5€

Cost per pip: 0,0075€

Leverage: 30

Can you please share me the formula how to calculate the the lot quantity. Thanks.

Basic Principles - Trading Operations - MetaTrader 5
is an instruction given to a broker to buy or sell a financial instrument. There are two main types of orders: Market and Pending. In addition, there are special Take Profit and Stop Loss levels. is the commercial exchange (buying or selling) of a financial security. Buying is executed at the demand price (Ask), and Sell is performed at the...

Never risk more than a small percentage of your account, certainly less than 2% per trade, 6% total. In code (MT4): Risk depends on your initial stop loss, lot size, and the value of the pair.
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.
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=0.1 Lots maximum.

William Roeder:
Never risk more than a small percentage of your account, certainly less than 2% per trade, 6% total. In code (MT4): Risk depends on your initial stop loss, lot size, and the value of the pair.
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.
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=0.1 Lots maximum.

Thanks a lot for the formula it looks like its working pretty good.

At the moment im using ATR value as stop, wich was working fine at minute chart. Most of the time i dont came in cross with any support or bounce line, but if so i would change the stop manually to get behind support.

Maybe later i will add a secondary function to calculate lot size on stop wouldnt be hard.

As i understood correctly DeltaPerLot in your linked function does TICKVALUE/TICKSIZE, atm its working for eur/usd, ger30, dow jones, gold.

Thanks for the tips with FreeMargin i included in my indicator.

Per Get "balance", "leverage", "sum last 5-10 historie", "minimal lot size".. own management indicator - Profit Trading - Technical Indicators - MQL5 programming forum #5 Why did you post your MT4 question in the Root / MT5 General section instead of the MQL4 section, (bottom of the Root page?)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon.

```// Calculate volume based on \$ risk and SL distance
double CalculateVolume(double InValue=0, double InStopDist=0)
{
double tick = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE) / SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE);
double calc1 = InStopDist*tick*_Point;
double calc2  = (calc1>0) ? InValue/calc1 : SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN); // Prevent zero divide
return(calc2);
}```