Tool
Position size
The cash at risk is chosen first. The stop distance and the pip value then set the lots. The tool does not decide where the stop should be.
The formula, in words
Cash at risk equals the account balance times the risk percent. The number of lots equals that cash amount divided by the stop distance in pips times the pip value of one lot. Pip value follows the same contract rules as the pip calculator, including a user-supplied rate when the account currency differs from the quote currency.