Loading…

Portfolio Value At Risk Monitor

The obvious way to estimate a multi-symbol account's one-day risk is to compute each position's own historical VaR separately, using only that symbol's own price history, and add the figures together. That throws away the one thing that actually determines whether risk adds up or cancels out - whether the symbols move together. Both directions of error are real: two genuinely uncorrelated positions diversify, so the naive sum usually overstates the account's true one-day risk, but two positions that are quietly correlated - two JPY crosses, two commodity currencies - can just as easily produce a real combined risk larger than the naive sum ever suggested, and that is the direction that actually hurts. This monitor runs a proper historical simulation instead. For each of the last N trading days it asks: what would that day's actual price move have done to every position currently open, all at once? Summing those simultaneous, symbol-specific moves into one number per historical day produces a distribution of whole-portfolio daily profit and loss that already captures real historical co-movement for free - no correlation matrix needs to be estimated separately, the historical data supplies it implicitly. The loss at the configured confidence percentile of that distribution is the one-day VaR, reported next to the naive per-symbol sum so the size, and direction, of the diversification gap is visible. Every money figure in the simulation is derived from each symbol's own tick value and tick size, never a hardcoded contract size, and scaled by each position's own lot size - the only formula that prices gold, indices and JPY crosses correctly alongside a standard FX pair in the same combined figure. Notes and limitations - Any position on a symbol with fewer than InpLookbackDays+1 daily bars cached locally is excluded from the simulation and counted as "skipped" in the panel - open that symbol's chart to build up history. - This is a historical simulation, not a parametric or Monte Carlo model: it assumes the recent past is a reasonable guide to tomorrow, which is the standard and honest limitation of the technique, not a defect specific to this implementation. - VaR is a loss threshold at a confidence level, not a hard cap - by construction a loss beyond the reported figure remains possible on the days the simulation itself classifies as the worst. - This tool never trades. It only reads open positions and price history and reports.

Expert advisor · MT5 · v1.0 · Free

About Portfolio Value At Risk Monitor

Portfolio Value At Risk Monitor is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 6 settings, such as Lookback days, Confidence level and Magic filter. MQL source code included.

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

Settings

SettingDefaultWhat it does
Lookback days250Historical daily bars used for the simulation
Confidence level95.0VaR confidence level, percent (e.g. 95 = worst 5% of days)
Magic filter0Only include this magic number (0 = all magic numbers)
Alert threshold percent5.0Alert when 1-day VaR exceeds this percent of equity
Alert cooldown minutes60Minimum minutes between repeat alerts
Redraw seconds30Seconds between recalculation and panel refresh

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: Alerts · Multi-Currency · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria