Loading…

Error 131 Volume Doctor

Error 131 (invalid volume) is one of the most common OrderSend failures and one of the least informative - the terminal tells you the volume was wrong, not which of the three separate reasons caused it. A lot size can fail because it is below the symbol's minimum, above its maximum, or not a whole multiple of its lot step from the minimum - three independent checks that most EAs only handle by normalising blindly and hoping. This script runs all three checks explicitly against the live MODE_MINLOT, MODE_MAXLOT and MODE_LOTSTEP values for a chosen symbol, and reports which ones the intended volume actually fails, rather than a single generic "invalid" verdict. It also checks the volume against estimated free margin, since a technically legal volume that still cannot be afforded fails at the broker for a different reason that gets confused with error 131 in practice. The lot-step check avoids the classic trap of dividing by MODE_LOTSTEP and flooring the result: 0.1 / 0.01 evaluates to 9.99999999999999998 in binary floating point, and a naive floor silently produces one fewer step than intended, quietly halving or shrinking a position. This script rounds to the nearest step with an explicit epsilon guard, both for the step-alignment check and for computing the nearest legal lot size to report back. Notes and limitations The margin check is an estimate using MODE_MARGINREQUIRED (margin needed per lot at current price) multiplied by the intended volume - it does not replicate every broker's exact margin formula (hedging, tiered margin above certain volumes, or currency conversion nuances can all shift the real figure slightly). Treat it as an early warning, not the broker's final word. Reads MODE_MINLOT/MODE_MAXLOT/MODE_LOTSTEP live at the moment it runs; these can differ from what an EA saw earlier if the broker changed limits between runs, or if the symbol had not fully synced into Market Watch yet (the script calls SymbolSelect first specifically to reduce that risk, but cannot guarantee history has finished loading). Only diagnoses volume-related rejection - it does not check stop distance against MODE_STOPLEVEL/MODE_FREEZELEVEL, price freshness, or any of the other reasons an OrderSend can fail. It answers exactly one question: "would this volume itself be accepted."

Script · MT5 · v1.0 · Free

About Error 131 Volume Doctor

Error 131 Volume Doctor is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 3 settings, such as Symbol, Intended lots and Intended is buy. MQL source code included.

Files in the download: Error131VolumeDoctor.ex5, Error131VolumeDoctor.mq5, Error131VolumeDoctor.txt.

Settings

SettingDefaultWhat it does
SymbolSymbol to check (blank = current chart symbol)
Intended lots0.07The lot size you intended to send
Intended is buytrueSide used only for the margin estimate (buy uses ask, sell uses bid)

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 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 · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria