The mathematical formula for calculating the correct lot size based on account balance, risk percentage, and stop loss.
This formula ensures you never risk more than your predetermined percentage on any single trade. It is the foundation of professional risk management and is used by institutional traders worldwide.
Account Balance — Your total trading capital (e.g., $10,000)
Risk Percentage — The fraction of your account you are willing to lose on this trade (typically 1-2%). Expressed as a decimal: 1% = 0.01
Stop Loss Pips — The distance from your entry to your stop loss, measured in pips
Pip Value per Lot — How much one pip of movement is worth for one standard lot. This varies by instrument:
Account: $10,000 | Risk: 1% | Stop Loss: 50 pips
Risk Amount = $10,000 x 0.01 = $100 Pip Value per Lot = 0.01 x 100 = $1.00 Lots = $100 / (50 x $1.00) = 2.00 standard lots Risk Amount = 2.00 x 50 x $1.00 = $100 ✓
Account: $5,000 | Risk: 2% | Stop Loss: 30 pips
Risk Amount = $5,000 x 0.02 = $100 Pip Value per Lot = 0.0001 x 100,000 = $10.00 Lots = $100 / (30 x $10.00) = 0.33 standard lots Risk Amount = 0.33 x 30 x $10.00 = $99.00 ≈ $100 ✓
from gfil_calculators.position_size import calculate_position_size
# XAUUSD example
result = calculate_position_size(10000, 1.0, 50, "XAUUSD")
print(f"Lots: {{result['lots']}}, Risk: ${{result['risk_amount']}}")
# Output: Lots: 2.0, Risk: $100.0
# EURUSD example
result = calculate_position_size(5000, 2.0, 30, "EURUSD")
print(f"Lots: {{result['lots']}}, Risk: ${{result['risk_amount']}}")
# Output: Lots: 0.33, Risk: $99.0