Loading…

Margin Requirement Table

"Can I afford to open this?" has a precise answer, and this script prints it for the whole Market Watch at once: the margin the broker takes to hold one lot of each symbol at the current price, the same figure scaled to a volume you choose, and the effective leverage - contract notional divided by margin - which is the honest way to compare how hard different instruments lean on your account. A symbol margined at 0.5% is 200:1 whatever the account leverage setting says, and crypto CFDs margined at 50% are 2:1 on the same account. Two traps are handled rather than ignored. The first is missing data. Brokers publish no margin figure at all for some symbols; the naive script prints a zero, which reads as "free to trade". Here the symbol moves to a separate no-data list with the reason stated, and the table only ever contains real numbers. The second trap is currency. The obvious leverage formula, contract size times price divided by margin, mixes quote currency with account currency and confidently prints roughly 30000:1 for USDJPY on a USD account. This script converts the notional into account currency through the tick value - the account-currency worth of one tick-size move - so the leverage column is right on every asset class, not just pairs that happen to be quoted in the account currency. Everything is computed at the current price. Margin scales with price on most calculation modes, so the table is a snapshot, stamped with its capture time. Notes and limitations - The figures are for a NEW standalone position at the current price. Margin discounts for hedged books, tiered margin by volume bracket, and weekend or news-time margin multipliers are broker-side rules this table cannot see. - Effective leverage needs a valid tick value to convert the notional into account currency. Where the broker publishes none, the column reads "n/a" rather than a guess. - On MQL4, "~init" rows are approximate by nature - verify against the broker's contract specification before relying on them. - Prices, and therefore margins, move. Re-run the script rather than reusing yesterday's table. - The script reads and calculates only. It opens nothing and modifies nothing.

Script · MT5 · v1.0 · Free

About Margin Requirement Table

Margin Requirement Table is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 4 settings, such as Custom volume, Scan all symbols and Export csv. MQL source code included.

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

Settings

SettingDefaultWhat it does
Custom volume0.10Second volume column, in lots
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