Leverage is the ratio between the size of a position and the money you need to put up to open it. At leverage of 1:30, a position worth £30,000 can be opened with £1,000 in the account. Margin is that £1,000, the portion of your balance the broker sets aside as security while the position is open.
How margin is calculated
Margin equals the notional value of the position divided by the leverage. One standard lot of EUR/USD at a rate of 1.08 is 100,000 euros, worth $108,000. At 1:30 leverage the margin required is $3,600. At 1:100 it would be $1,080, and at 1:500, $216.
The margin is not a cost. It is returned when the position is closed. What it does is limit how much you can have open at once, because the broker will not let you open a position whose margin exceeds the free margin in the account.
MetaTrader 5 shows this at the bottom of the terminal. Balance is the money in the account. Equity is balance plus or minus the floating profit on open positions. Margin is the total held against open positions. Free margin is equity minus margin. Margin level is equity divided by margin, as a percentage, and it is the number the broker watches.
Margin call and stop out
If losses on open positions pull equity down until the margin level falls below the broker's margin call level, often 100 per cent, the terminal warns you and will not accept new orders. If it falls to the stop-out level, often 50 per cent, the broker begins closing positions, largest loss first, until the level recovers. A stop out is not a stop loss. It is the broker protecting itself, and it happens at whatever price is available.
The UK limits
For retail clients in the UK the FCA caps leverage at 1:30 on major currency pairs, 1:20 on non-major pairs, gold and major indices, 1:10 on other commodities and minor indices, and 1:2 on cryptocurrencies. Brokers must also close positions before the account goes below zero. Clients who qualify as professional can be offered higher leverage and lose that protection. Outside the UK and EU, retail leverage of 1:500 and beyond is common.
Higher leverage does not make a trade more profitable. It reduces the margin needed to hold it, which allows a larger position for the same deposit. The risk of a trade is set by its size and its stop, not by the leverage figure on the account.
A £10,000 sterling account at 1:30 leverage holds three positions: 0.5 lots of EUR/USD, 0.1 lots of gold and one contract on the FTSE 100. The margin for each is its notional value divided by its leverage cap: roughly £1,400 for the euro position at 1:30, £950 for the gold at 1:20, and £410 for the index at 1:20, about £2,760 in total. Free margin is about £7,240, and the margin level is above 350 per cent. There is room for more positions, but each one reduces the buffer, and a sharp adverse move on all three at once would reduce it faster.
A multi-strategy EA can hold several positions across different markets at the same time, and each one consumes margin. On a small account with UK leverage caps, free margin can run out before the EA's risk rules would have stopped it opening new trades. When that happens the broker rejects the order and the EA logs an error.
This is a second reason, after the minimum lot, that EAs carry minimum balance recommendations, and the balance needed rises with the number of markets the EA trades and with the risk setting chosen. A careful EA checks free margin before placing an order and treats a rejection as a reason to stand aside rather than retry. It should also never rely on the broker's stop out as a safety net. By the time a stop out happens, the EA's own drawdown limits should have halted it long before.