Loading…

Equalise All Lot Sizes

Scaling in at varying sizes leaves a ragged book: 0.30, 0.10 and 0.05 on the same symbol and side, where every later management action - partial closes, stop moves, per-position risk sums - now needs three different numbers. Equalising the sizes back to a common denominator is tedious by hand and easy to get wrong, because it is partial-close arithmetic repeated under time pressure. The first design decision is the direction. This script only ever REDUCES: each symbol-side group is brought down to the size of its smallest position. The alternative - topping the small ones up to the largest - would mean a tidy-up script that adds exposure, and a tool run to reduce mess must never be able to increase risk. Nothing is opened, ever. Buys and sells are separate groups on purpose: letting the small side of a hedge dictate the size of the large side would change the net position the trader deliberately carries. The second is the volume arithmetic, which is where naive versions break. Each reduction is floored onto the broker's lot step, never rounded up, because rounding up closes more than the plan announced - and the division is nudged by an epsilon first, since 0.1/0.01 is 9.999... in binary and flooring that raw loses a whole step. The closed slice must itself be a volume the broker accepts, and the volume left open must stay at or above the minimum. A position that cannot satisfy all three constraints - say its excess over the target is smaller than the minimum closeable amount - is skipped with the reason printed. It is never quietly closed whole and never cut below the target. The whole plan is computed from one snapshot of the book, printed to the journal line by line (ticket, from, to, amount closed), and summarised in a confirmation prompt before the first close is sent. What you confirm is what gets executed. Notes and limitations - Market positions only. Pending orders have no filled size to equalise. - Reduces only, never opens. If you want the small positions enlarged instead, that is a risk-increasing operation this script refuses to be. - The target is the smallest position in the group at snapshot time. If something else closes that smallest position mid-run, the plan already confirmed still executes - the target does not re-rank mid-flight. - A position whose excess over the target is below the broker's minimum closeable volume stays as it is, with the reason printed. Groups of one position are trivially equal and left alone. - Partial closes realise the profit or loss on the closed slice at market price, including spread. Equalising a large book has a real cost. - On MQL4 the reduced positions continue under new ticket numbers; anything tracking the old tickets (an EA, a journal) should be aware.

Script · MT4 · v1.0 · Free

About Equalise All Lot Sizes

Equalise All Lot Sizes is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 6 settings, such as Current symbol only, Magic filter and Slippage pips. MQL source code included.

Files in the download: EqualiseLotSizes.ex4, EqualiseLotSizes.mq4, EqualiseLotSizes.txt.

Settings

SettingDefaultWhat it does
Current symbol onlyfalseRestrict to this chart's symbol
Magic filter-1Magic number (-1 takes every magic)
Slippage pips3Slippage tolerance, in pips
Max retries5Attempts per position before giving up
Retry wait ms500Pause between attempts, milliseconds
Confirm firsttrueAsk for confirmation before closing

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Volume · Risk & Lot Size · Alerts · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria