How margin is calculated
Margin is the deposit the broker holds while a position is open. It is the position value divided by the leverage.
The position value is price ร contract size ร lots, converted to your account currency. With 1:30 leverage you put up 1/30 (about 3.3%) of that value.
In the EU, retail clients are capped by ESMA at 1:30 on major forex pairs, 1:20 on gold, non-major pairs and major indices, and 1:10 on other commodities. The calculator starts with those limits.
Margin = (Price ร Contract size ร Lots ร Conversion rate) รท Leverage
Example: gold (XAUUSD)
Gold at 2,400, 0.10 lots = 10 oz = $24,000 position value. At 1:20 the margin is $24,000 รท 20 = $1,200.
Questions
Is margin the amount I can lose?
No. Margin is a deposit, not a cost. What you can lose is set by your stop loss and position size, which is why you should size trades with the lot size calculator, not by margin.
What happens if free margin runs out?
If losses eat the free margin, the broker sends a margin call and then closes positions automatically (stop out). EU brokers must close positions when equity falls to 50% of the margin used.
Is higher leverage better?
Higher leverage only lowers the deposit. It makes it easier to open positions that are too big for the account. Size by risk, not by available margin.