Loading…

Drawdown Stress Test By Shock

"What happens to my account if the dollar drops two percent" is a question most traders answer by watching it happen. This script answers it in advance by repricing every open position under a shock you define, then reporting the projected equity and, if the account uses a percentage stop out, whether the shock alone would breach it. Shocks are defined per currency, not per symbol, because that is how real moves propagate - a dollar shock affects every USD pair at once. For a recognised pair the price move is taken as the base currency's shock minus the quote currency's shock, a standard first order approximation. Anything that is not a clean three-letter-plus-three-letter pair - gold, an index, a crypto symbol - has no currency pair to look up, so it falls back to one flat non-forex shock input instead of being silently skipped or, worse, misread as a currency pair it is not. The money conversion is the part most scripts like this get wrong. It is tempting to multiply a price move by a fixed 100000 and call it done, and that number is simply false for gold, most indices, and any broker that quotes a non-standard contract size. This script reads tick value and tick size from the broker for every symbol and derives money per price unit from those two numbers, which is correct regardless of what the instrument actually is. The result is also scaled by each position's own lot size, so a 0.01 lot and a 5 lot position under the same shock are never reported as carrying the same money impact. Notes and limitations - The base-minus-quote rule is a first order approximation. It ignores cross-currency triangulation effects and any correlation between the shocks you enter - entering unrealistic combinations produces an unrealistic result, the same as any what-if tool. - Only open positions are repriced. Pending orders have no current floating result to shock. - The stop out warning only applies to accounts using a percentage stop out level. A money-based stop out level is not comparable to the projected margin level percentage and is skipped, noted in the log. - This is a static, one-shot reprice, not a path simulation - it does not model margin calls triggering partial closes along the way. - Nothing here places, closes or modifies an order or a position on either platform. It only reads.

Script · MT4 · v1.0 · Free

About Drawdown Stress Test By Shock

Drawdown Stress Test By Shock is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 5 settings, such as Currency shocks, Non forex shock percent and Include pending orders. MQL source code included.

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

Settings

SettingDefaultWhat it does
Currency shocksUSD:-2,EUR:1,JPY:-1Currency shocks, CCY:percent, comma separated
Non forex shock percent-2.0Price shock for symbols with no currency pair (metals, indices, crypto)
Include pending ordersfalseNote pending orders in the report (no floating P/L)
Write report filetrueWrite a per-position impact CSV
Alert resulttrueAlert with the projected equity outcome

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: Gold (XAUUSD) · Alerts · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria