Scenario Matrix Evaluator
A single stress test - "what if EURUSD drops 100 points" - only answers one question about one axis of risk. In practice a move big enough to hurt is usually ALSO a move that widens spreads and degrades execution, exactly when clean fills matter most. Testing price alone systematically understates the worst realistic case, because it silently assumes execution stays calm while price is in freefall. SME_EvaluateSurface evaluates every combination of a price-shock grid against a spread-widening-multiplier grid and returns a payoff surface: for each cell, every position's P&L from the hypothetical price move (direction-aware, converted through that SYMBOL'S OWN tick value so a JPY cross and a major are weighted correctly) minus the assumed execution cost at that cell's spread multiplier applied to the position's current spread. SME_WorstCase then reports the single worst cell across the whole grid - the combined price-and-execution-stress scenario, not just the worst price alone. Per-point dollar value comes from MarketInfo(symbol, MODE_TICKVALUE), the broker's own published figure, which already reflects each instrument's real contract size and quote-currency conversion - nothing is hardcoded per instrument. The surface itself is a flat 1D array in row-major order (cell (i, j) at index i*volCount+j), the same flat-matrix convention this catalogue's ComponentRiskDecomposition.mqh uses, since MQL4 has no dynamic 2D array. Notes and limitations - SME_MAX_GRID (41) bounds each grid axis independently - raise it in the header if a review genuinely needs a wider grid. - The price-shock axis applies the SAME point delta to every position's own symbol, uniformly. It is a parallel-shift scenario, not a per-symbol independent shock grid - a book spanning very different instruments (e.g. a major FX pair alongside gold) should be evaluated with separate SME_EvaluateSurface calls per instrument group if their shocks should not move together. - The spread-widening axis models execution cost as a multiple of the CURRENT spread at evaluation time, read once at the start of the call - it does not re-query the market per cell, so a call made during an already-wide spread will project that wide starting point forward rather than a calm one. - SME_EvaluateSurface fails outright (returns false) if any position's symbol has no valid tick value, e.g. not selected in Market Watch - this is deliberate: producing a partially-wrong surface silently would be worse than refusing to produce one at all.
Script · MT5 · v1.0 · Free
About Scenario Matrix Evaluator
Scenario Matrix Evaluator is a script for MetaTrader 5. It has 4 settings, such as Shock step points, Shock steps and Buy lots. MQL source code included.
Files in the download: ScenarioMatrixEvaluator.mq5.mqh, ScenarioMatrixEvaluator.txt, ScenarioMatrixEvaluatorDemo.ex5, ScenarioMatrixEvaluatorDemo.mq5.
Settings
| Setting | Default | What it does |
|---|---|---|
| Shock step points | 100 | Spacing between price-shock grid points, in points |
| Shock steps | 5 | Grid runs +/- this many steps (grid width = 2*steps+1) |
| Buy lots | 1.0 | Lots of the synthetic buy position |
| Sell lots | 0.4 | Lots of the synthetic sell position |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Grid · EURUSD · MT5 Script · MQL5 Source Code