Loading…

Max Lots Before Margin Call Table

"How big can I still trade before I'm in danger" is usually answered by watching the margin level number drop after the fact. This script answers it in advance, symbol by symbol, by solving the margin level formula directly rather than searching for the answer by trial and error. Margin level is Equity divided by Margin, times 100. Opening more volume raises Margin (the denominator) without raising Equity (the numerator) at the instant of the fill, so margin level falls in one direction as size increases. That makes the breakpoint solvable algebraically: the margin that would push the account down to a given level is Equity times 100 divided by that level, minus margin already used. Dividing by each symbol's own per-lot margin requirement, then flooring to the symbol's lot step, gives the largest size the broker would actually accept before crossing the line - never a size one tick over it. Two thresholds are shown side by side: the broker's actual margin call level (or the account's own stop-out level when no figure is typed in), and a second, tighter level with a safety buffer subtracted, for a trader who wants to see the size that keeps some room to spare, not the size that lands exactly on the edge. Margin per lot is read from MODE_MARGINREQUIRED where the broker publishes it, and MODE_MARGININIT as a flagged fallback otherwise - some brokers quote MARGININIT in the symbol's margin currency rather than account currency, so fallback rows are marked rather than presented with the same confidence as a real MARGINREQUIRED figure. Notes and limitations - This is a static snapshot. Equity, used margin and quotes all move on every tick and every new position; the table is only valid at the moment it was printed and should be re-run before relying on it. - A symbol with no published margin figure at all is listed separately in a "no data" section, never silently shown as zero margin. - The figures assume the new volume is opened in isolation on top of current exposure. They do not model cross-margining or hedged-position margin reduction some brokers apply when a new position offsets an existing one on the same symbol. - Rows falling back to MODE_MARGININIT are marked and should be treated as approximate, since that field is not always guaranteed to be in account currency.

Script · MT5 · v1.0 · Free

About Max Lots Before Margin Call Table

Max Lots Before Margin Call Table is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 5 settings, such as Margin call level, Safety buffer and Scan all symbols. MQL source code included.

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

Settings

SettingDefaultWhat it does
Margin call level100.0Margin call level, % (0 = read from account if possible)
Safety buffer10.0Extra % below margin call level treated as the real limit
Scan all symbolsfalseScan every known symbol, not only Market Watch
Export csvfalseAlso write the table to a CSV file
Csv delimiter,CSV delimiter (first character is used)

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 · Alerts · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria