DEV Community

Cristian Lungu
Cristian Lungu

Posted on

The input most MT4/MT5 trading bots get wrong: position size

Ask someone why their trading bot blew up and they'll tell you about the strategy. The real answer is usually more boring: the position size was wrong, so a normal losing streak turned into a dead account.

Most EAs I'm asked to fix hardcode the lot size — lots = 0.10, forever. That's the bug. Here's why it kills accounts, and the handful of lines that fix it. It's MT4/MT5 here, but the logic is the same anywhere you place orders in code.

Why a fixed lot quietly kills an account

Two reasons.

Your risk swings with volatility. A 0.10-lot trade with a 15-pip stop and a 0.10-lot trade with a 150-pip stop are not the same trade — one risks 10x the other. With a fixed lot, your real risk per trade is whatever the market's volatility happens to be that day. You're not choosing your risk; the market is choosing it for you.

Losses compound against a fixed base. A hardcoded lot is sized off your starting balance. After a drawdown you're still betting the same absolute size on a smaller account, so your percentage risk climbs exactly when you can least afford it. That's the math that turns a rough week into a blown account.

The fix: choose the risk, derive the lot from the stop

Flip it around. You don't choose the lot — you choose the risk (say 1% of balance), and the lot falls out of the stop distance:

  • money at risk = balance x 1%
  • loss-if-stopped, per 1.0 lot = stop distance x tick value
  • lot = money at risk / loss-per-lot (then snap to the broker's volume step)

Now every trade risks the same 1%, whether the stop is 15 pips or 150. The size shrinks automatically when the stop is wide or the account is smaller. Nothing about the strategy changed — only the thing that decides whether you're still here next month.

Pair it with an ATR-based stop (stop = a multiple of Average True Range) and the whole system breathes with volatility: wider stops in fast markets, smaller lots to match, constant risk throughout.

Does the discipline actually show up in the numbers?

I put exactly this — trend filter, pullback entry, ATR stop, 1% risk-based sizing — into a sample EA and ran it through the MT5 Strategy Tester on a year of XAUUSD H1 data:

  • Return: +33.7%
  • Profit factor: 1.45
  • Max drawdown: 8.0%
  • 114 trades, ~44% win rate at 2:1 reward-to-risk

The number that matters there isn't the return — it's the 8% drawdown. That's what risk-based sizing buys you: the account bends instead of breaking, so you're still around when the winners show up. Note the win rate is only ~44%; it's profitable purely because the size and the reward-to-risk are disciplined. Fixed lots would have made the same strategy a much rougher ride.

You can see the sample EA, its adjustable parameters and the equity curve here:
https://darling-kataifi-559215.netlify.app

The takeaway

Spend your time on the strategy — but the line that decides whether you survive long enough for the strategy to matter is the one that sizes the trade. If your EA has lots = 0.10 hardcoded anywhere, that's the first place I'd look.

I build and fix MT4/MT5 EAs and other execution software at Quiet Machines — risk-based sizing, clean stops, backtests you can actually read. If your bot's risk feels like a guess rather than a number you chose, that's the work I do.

— Cristian Lungu · https://contra.com/lungu_cristian_d7nm4wbh

Top comments (0)