The Risk-Based Lot Size Calculator is a lightweight MQL5 script that removes the guesswork from position sizing. Instead of manually working out how many lots to trade, you enter a risk percentage and a stop loss distance, and the script instantly reports the correct lot size for the current symbol and account balance.

Many traders lose money not because their strategy is wrong, but because their position size is wrong. Risking too much on a single trade can damage an account even with a good strategy, while risking too little limits growth. This script ties position size directly to a fixed percentage of account risk, so every trade carries a consistent, controlled amount of risk.

External variables used:

InpRiskPercent - the percentage of account balance you are willing to risk on the trade (default 1.0%).

InpStopLossPips - the distance between entry price and stop loss, measured in pips (default 20 pips).

How it works: the script reads the current account balance together with the selected symbol's tick value, tick size and volume constraints (minimum lot, maximum lot, lot step). It then works out the lot size needed so that, if price moves against you by the specified number of pips, the loss equals the chosen risk amount. The result is rounded down to the nearest allowed lot step and clamped between the broker's minimum and maximum volume. The final lot size, together with the full calculation breakdown, is shown on the chart and printed to the Experts log.

Because it reads live broker parameters instead of relying on hard-coded pip values, the script works on any symbol and any account type. Simply attach it to a chart, enter the risk percentage and stop loss in pips, and read the suggested lot size from the chart comment.