Advertisement IC Markets

Lot sizing function gotchas across JPY pairs and gold, the bug that over-risked me

Share, develop, and backtest custom MQL4/MQL5 Expert Advisors, Python data-scraping scripts, trading bots, and automated market alert systems.
Post Reply
Fairman
Posts: 2602
Joined: Tue Jul 21, 2026 7:11 am
Location: Abuja

Lot sizing function gotchas across JPY pairs and gold, the bug that over-risked me

Post by Fairman »

Lot sizing function gotchas across JPY pairs and gold, the bug that over-risked me

wrote an equity based position sizing function for my EA, risk a fixed percent per trade based on the stop distance. Worked on EURUSD in testing. Then I put it on USDJPY and gold and the risk per trade was completely wrong, either far too big or tiny.

The problem was tick value and tick size. Different symbols have different contract sizes, and the value of one pip or point isn't the same. On JPY pairs a pip is 0.01 instead of 0.0001, and on gold the point size depends on how the broker quotes it. My function assumed a pip meant the same thing everywhere.

The fix was to read the symbol's tick value and tick size from the platform each time, and calculate risk from those instead of hardcoding anything. I also round the lot to the broker's volume step and clamp it between the minimum and maximum allowed. Then I print the calculated money at risk to the log for every order so I can see if it matches what I intended.

Test it on a demo with each symbol you plan to use and check one trade manually before trusting it.
It’s Fairman :geek:
Recommended broker for automated trading & scalping IC Markets
Fairman
Posts: 2602
Joined: Tue Jul 21, 2026 7:11 am
Location: Abuja

Re: Lot sizing function gotchas across JPY pairs and gold, the bug that over-risked me

Post by Fairman »

One more gotcha that caught me after I fixed the tick value issue. If your account currency is not the quote currency of the pair, the tick value the platform gives you can change during the day as exchange rates move. For most pairs it is a small difference, but for something like gold on a non dollar account it adds up. I now read the tick value fresh right before every order instead of caching it once when the EA starts.
It’s Fairman :geek:
Fairman
Posts: 2602
Joined: Tue Jul 21, 2026 7:11 am
Location: Abuja

Re: Lot sizing function gotchas across JPY pairs and gold, the bug that over-risked me

Post by Fairman »

Also worth checking what your broker uses as the volume step. Some allow 0.01 lots, some only allow 0.1 on certain symbols, and a few have odd minimums on gold or indices. My function was calculating a sensible size and then the order got rejected because it was not a valid step. Rounding down to the nearest valid volume fixed it. Rounding down rather than to the nearest also means the risk only ever comes out slightly lower, never higher, which is the side I want to be wrong on.
It’s Fairman :geek:
Post Reply