How to Calculate Lot Size in MetaTrader 5 Using Stop Loss and Trade Risk
Imagine you have found a setup, marked your stop-loss level and opened the order window in MetaTrader 5. The terminal asks for a volume. You might reach for the same 0.10 lots you used yesterday. But yesterday's stop was 20 pips away, and today's is 60 pips away. On the same instrument, under the assumptions in this example, the price move would now cost three times as much at the same volume. I'll show you how I work out the volume before entering a trade and how I put the same calculation into an Expert Advisor.
If you are studying how the market's trading range changes, you can also take a look at VR ATR Pro. For the examples below, I start with a stop level already chosen according to the rules of the strategy. That gives me a definite price to work with, whether the strategy places its stop using chart structure or a volatility measure.
What I write down before sizing a trade
I start with the direction, the expected entry price and the assumed exit price at the stop. Then I write down the amount of money the strategy allows for that trade. If the budget is expressed as a percentage, I convert it to the account currency. With $2,000 in equity and a 1% budget in a worked example, the trade has $20 available for its planned loss and any costs included in that budget. These figures make the arithmetic easy to follow.
Decide which account value your strategy uses as the basis for the percentage. Balance and equity can differ while trades are open. With a $2,000 balance and $1,800 in equity, 1% is either $20 or $18, depending on the rule you chose. I use equity in this example because I want the new trade's budget to reflect the state of the account when I calculate it. If the budget is based on the balance at the start of a trading session, I keep that reference value separate and apply it consistently.
I make a note of the starting prices even when I am doing the calculation by hand. A quote can move between the moment I see a setup and the moment I prepare the trade. If the proposed entry moves and the stop stays in place, the distance changes. If other positions are open, equity can also move during that interval. Writing down both inputs makes it easier to repeat the calculation and explain why the volume changed.
In earlier posts I looked at the minimum trading deposit and trade volume in MetaTrader 5. Here I take one position through the full workflow. I'll estimate the loss for a reference volume, choose a valid lot size, recalculate the cost and check whether the account can support the order.
A worked EURUSD example
Consider a EURUSD buy on a USD-denominated account. The expected entry is 1.10500 and the assumed stop exit is 1.10100. The price difference is 0.00400. With a five-digit quote, that is 400 terminal points, or 40 pips in the usual convention for this pair. This is why I keep the actual prices in my notes. The phrase “40 points” is easy to misread when someone switches between a terminal field and a discussion about pips.
Suppose the symbol specification defines one lot as 100,000 units of the base currency. A move of 0.00400 then produces a $400 loss for one lot between the assumed prices. On 0.10 lots the loss would be $40. On 0.05 lots it would be $20, and on 0.01 lots it would be $4. For now, I am estimating the price-driven result and leaving commission and other additional costs for a separate step.
| Volume | Estimated loss from a 1.10500 entry to a 1.10100 exit |
|---|---|
| 1.00 lot | $400 |
| 0.10 lots | $40 |
| 0.05 lots | $20 |
| 0.01 lots | $4 |
With a $20 budget, the preliminary size is 0.05 lots. I divide $20 by the $400 reference loss and get the fraction of a lot the budget can cover. I then reverse the calculation. Multiplying $400 by 0.05 gives $20 again. That takes a few seconds and catches errors such as using 0.5 when the intended order size was 0.05.
Now keep the same entry and move the stop to 1.09900. The distance is 60 pips, so the loss for one lot is $600 under the same assumptions. The $20 budget gives a preliminary volume of approximately 0.0333 lots. If the permitted step is 0.01, I test 0.03 lots. It produces an $18 price-driven loss. At 0.04 lots, the loss would already be $24. A relatively small change in the stop price can move the final order by several valid volume increments.
Volume steps and trading costs
Every symbol has its own minimum and maximum order volumes and its own volume step. In MQL5 I read those values using SYMBOL_VOLUME_MIN , SYMBOL_VOLUME_MAX and SYMBOL_VOLUME_STEP . A step of 0.01 is convenient for the example, but I use the traded symbol's settings in an EA. A symbol that trades in increments of 0.25 shows why counting decimal places alone is insufficient. A value such as 0.37 has two decimal places and still falls outside that increment.
When the risk budget is an upper bound, I choose the largest permitted volume that meets it, subject to any other limits in the strategy. Say the raw calculation gives 0.0375 lots and the symbol's minimum and step are both 0.01. I check 0.03 lots. Ordinary rounding to two decimal places gives 0.04, which lies above the planned size. This is one of the first details I review when a position-sizing feature consistently produces slightly more risk than the input specifies.
Let's put commission back into the first EURUSD example. The price move costs $400 per lot. Suppose the round-trip commission is $8 per lot and scales with volume. The combined estimate is $408 per lot, so a $20 budget gives approximately 0.0490 lots. At a 0.01 step, I now check 0.04 lots. Its total estimated loss is $16.32. At 0.05 lots, the estimate is $20.40, which exceeds the example budget even though the price move alone costs exactly $20.
Some fee schedules have a minimum charge per operation or apply different rates under different conditions. For such a schedule I check the actual candidate volume against the applicable tariff. Suppose the proportional fee on a small order is less than the minimum charge. The budget has to cover the minimum that actually applies to the opening and closing operations. Working backward from a simple per-lot estimate is still useful for finding a candidate. The check on the final amount is what decides whether to use it.
There is also a case where no valid size fits. If the budget is $3 and the minimum volume of 0.01 lots produces a $4 loss before commission, the current setup has no qualifying trade size. I log that reason and skip the signal. If the strategy later produces a valid entry with a different stop distance, it gets a fresh calculation using the new prices. In a manual workflow, identifying this case early saves time searching the terminal for a smaller amount the symbol will never accept.
Which prices I use for buys and sells
For a market buy, I use Ask as the expected entry reference. For a market sell, I use Bid. I also check the side of the quote on which the position closes. A buy closes on the Bid side, and a sell closes on the Ask side. Once I have expressed both inputs as the prices of the respective operations, I can see what has already been accounted for in the entry-to-exit spread and avoid charging for the same difference again.
Suppose Bid is 1.10480 and Ask is 1.10500. For a buy I use 1.10500 as the expected market entry. With an assumed stop execution at 1.10100, the distance is 0.00400. If I accidentally use the displayed Bid as the entry, the distance shrinks to 0.00380. On the example contract the loss for one lot would appear to be $380, even though my assumed entry and exit imply $400. That difference matters whenever the candidate volume is close to a risk or volume threshold.
For a sell, suppose the expected Bid entry is 1.20000 and the assumed stop execution on the Ask side is 1.20400. The distance is again 40 pips. If the strategy draws its reference level on a Bid chart, I check how that level relates to the Ask price that closes the short position. The shorter the stop, the more useful this check becomes. A few points can account for a noticeable share of the entire move.
At the point of calculation, the entry and exit are assumptions. A fast move or a price gap can produce a different fill and a larger loss. During testing I record the estimated result between the assumed prices and the result at the actual fills. The difference helps me tell whether a mismatch came from position sizing, an execution price change or a cost I had left out of the initial estimate.
Implementing the calculation in MQL5
I use OrderCalcProfit() to estimate the price-driven result. It takes the order direction, symbol, reference volume, opening price and closing price. A successful call gives an estimated result in the account currency. This is useful when the account currency differs from the quote currency or when the instrument uses a different profit calculation from the simple EURUSD example.
One lot is a convenient reference if it is a valid volume for the symbol. Any suitable reference volume works for this preliminary step. Suppose 0.10 lots produces an estimated result of −$40 and the trade budget is $20. The initial size is 0.10 × 20 ÷ 40 = 0.05 lots. After converting that result to a permitted volume, I call the function again with the actual candidate. That second call gives me the price-driven loss to use in the final budget check.
I validate the prices and the result before taking the magnitude of the loss. For this initial stop scenario, a buy has a stop below the entry, and a sell has a stop above it. I check whether the function succeeded and whether the returned result has the expected negative sign. Taking an absolute value immediately can hide a reversed price pair because a positive result would then look like a plausible monetary loss. If the inputs or the calculation fail, the journal records enough detail to diagnose the issue.
- Get the expected entry and stop exit prices and validate them for the direction of the trade.
- Read the chosen account value and convert the trade's risk budget to money.
- Read the symbol's volume limits and step, then choose a valid reference volume.
- Use OrderCalcProfit() to estimate the reference loss and calculate an initial lot size.
- Choose a permitted volume and calculate the estimated result for that exact size.
- Apply the applicable commission estimate and any cost buffer defined by the strategy. Test a lower volume if the combined estimate exceeds the budget.
- Estimate margin and check the completed trade request before sending it.
I also test values close to a volume-step boundary. A number such as 0.03 may be stored with a small floating-point difference. A careless floor operation can then remove a full increment when the value already belongs on the permitted grid. I work in volume increments for the grid calculation and check the final monetary result again. That makes it possible to distinguish a genuine risk reduction from an arithmetic artefact in the log.
For debugging, I record the symbol, order direction, entry and exit assumptions, equity, monetary budget, reference result, raw size, final volume and estimated costs. If a function call fails, I record the error with the relevant inputs. A line that only says “volume = 0.01” gives me very little to work with. The full calculation shows whether the choice came from a wide stop, a small budget, volume rounding or a margin constraint.
Checking margin after the risk calculation
Suppose the permitted volume gives a $16.32 total estimate and fits within the $20 trade budget. I still need to check whether the account can open the position. I use OrderCalcMargin() for a preliminary estimate of the margin for the proposed operation. It evaluates the operation under current conditions without including existing positions or pending orders in that calculation.
Next I run OrderCheck() on the actual request and inspect the returned result. It is worth testing this step with an existing position on the same symbol. On a netting account, the new order can add to or reduce that position. On a hedging account, opposite positions can coexist, and the applicable margin treatment depends on the account and symbol conditions. Those cases are easy to overlook if all the tests start with an empty account.
Free margin is relevant to the funds available to support the position. The estimated stop loss is relevant to the money that could be lost under the assumed exit. I apply both checks. If the volume meets the risk budget but the request fails the margin check, I inspect the reason and test a smaller allowed size when the strategy permits it. If the account has ample free margin and the loss estimate is over budget, I still reduce the volume or skip the entry.
I cover the account side of the calculation in more detail in my article on margin in MetaTrader 5. In practice, keeping the two checks visible makes it easier to diagnose order sizing when an EA moves to a different symbol or account.
What I check in the Strategy Tester
I start with a single trade I can reproduce by hand. I use the same symbol, the same prices and the same budget in the manual calculation and in the EA. Then I test a wide stop where the smallest volume exceeds the budget, and a short stop where the preliminary size reaches an order-volume or strategy limit. For each case I write down the expected action before running the test. The EA might use a smaller valid size, cap the volume, or skip the trade and record the reason.
Next I add existing positions. Suppose the new signal has a planned loss of $20 and two earlier trades have planned losses of $20 and $25 from their respective entries. In a simple scenario where all three reach those stops, the total planned loss measured from entry is $65. That is useful when the strategy limits exposure over a series of trades. To estimate the additional drawdown from current equity, I instead measure the open positions from their current marks to the assumed exits. Their floating result is already reflected in equity.
I also check when the EA takes its price snapshot. A signal may arrive on one tick, and the Ask or Bid may change before the request is ready. When that happens, I want the journal to show the price used in the volume calculation and the price used in the trade request. Once I can see the difference, I can test the strategy's rule for recalculating the volume or skipping an entry after a material price change.
Finally, I compare the estimate with the executed trade. If the trade closed at the expected price, I check the fees and the assumptions about the instrument. If the fill price moved, I measure the effect of the execution difference separately. That gives me a practical way to review the whole position-sizing process using actual trades from the test. I share more examples from EA development on my English-language Telegram channel.
Recommendations
Start with one line in your notes containing the symbol, direction, entry, stop and budget in the account currency. Work out the loss for a reference volume, choose a size the symbol accepts, and recalculate the risk including the costs that apply. If the result looks wrong, check the prices and units first. Then review the symbol specification and the margin estimate.
If you trade manually, try calculating two setups on the same instrument, each with a different stop distance that your strategy would actually use. Keep the monetary budget fixed and look at how the permitted volume changes. With a wider stop, the volume will generally need to be smaller. Recheck the final number after rounding and adding commission. Those two steps often explain why the size you can enter differs from the first number you calculated.
If you are writing an EA, save the calculation for each signal during testing. You can then reconstruct why it selected 0.03 lots, rejected the trade, or reduced the volume after a check. If you would like to discuss how you handle this in MQL5, feel free to add me through my MQL5 profile.
Tags: MetaTrader 5, MQL5, lot size, Stop Loss, position sizing, risk management, Expert Advisors.


![[XAUUSD]: Weekly Liquidity Activation Points (LAP), November 30-December 4, 2026 [XAUUSD]: Weekly Liquidity Activation Points (LAP), November 30-December 4, 2026](https://c.mql5.com/6/1059/splash-preview-782550.jpg)
