Risk budget = capital × risk percentage. Risk per unit = the distance from entry to stop. Quantity = risk budget ÷ risk per unit, rounded down.
Two things people get wrong. They round the quantity up when it comes out awkward — which quietly raises the risk above the budget they just set. And they widen the stop to fit a size they had already decided on, which is the same mistake wearing a different hat.
Brokerage, STT, exchange charges, GST, stamp duty and slippage all come out of the result. For derivatives, margin requirements may cap the size well below what this returns. Treat the number as a ceiling, not a target.