Loading…

Margin Scenario Drill Scheduler

Most traders only find out their margin buffer is thin at the exact moment an adverse move already hit it. This EA rehearses that scenario ahead of time, once a day at a declared server-time, and writes the result to a CSV readiness log. Two checks run in every drill, both read-only - neither sends a real order. The first tests whether the account could still open a hypothetical new order of a declared size, using the account's own AccountFreeMarginCheck() rather than a guessed number. The second shocks every currently open position's price by a declared adverse percentage and recomputes the resulting margin level, using each position's own symbol tick value and tick size - never a hardcoded contract size, since gold, indices and JPY crosses all price differently. The stressed margin level is classified OK, WARNING or CRITICAL against two declared thresholds, and an Alert() fires on anything worse than OK if enabled. Notes and limitations The stress test applies the same adverse percentage to every open position's price at once, regardless of direction - it assumes every position moves against you simultaneously. That is a deliberately conservative worst case, not a forecast, and does not model correlation between symbols. AccountFreeMarginCheck() reflects the broker's own margin formula for a fresh order at current prices; it is not a substitute for the stress projection above, which reprices existing exposure instead of testing a new order. The drill runs once per calendar day at the declared time; if the terminal or EA was not running at that moment, that day's drill is simply skipped, not caught up retroactively. This EA never trades and never modifies an order - both checks are read-only calculations.

Expert advisor · MT4 · v1.0 · Free

About Margin Scenario Drill Scheduler

Margin Scenario Drill Scheduler is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 7 settings, such as Drill time, Scenario lots and Stress adverse move pct. MQL source code included.

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

Settings

SettingDefaultWhat it does
Drill time07:00Server time HH:MM the daily drill runs at
Scenario lots0.10Hypothetical new-order size tested for margin headroom
Stress adverse move pct1.0Adverse price move %% applied to every open position for the stress test
Warning margin level pct200.0Stressed margin level %% at/below which readiness is WARNING
Critical margin level pct100.0Stressed margin level %% at/below which readiness is CRITICAL
Alert on warning or worsetrueTurn this alert on or off
Log file nameMarginScenarioDrill.csvFile written under MQL4\Files\

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: Alerts · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria