Risk Of Ruin Monitor
Risk of ruin is usually quoted as an abstract textbook number for a generic edge and payoff. This EA computes it from the trader's own recent closed trades instead: it samples up to a configurable number of the most recent matching trades, derives the win rate and the average win and loss in account currency, and combines them into an edge figure using the standard E = (p*avgWin - (1-p)*avgLoss) / (p*avgWin + (1-p)*avgLoss) formula. That edge, together with the number of "risk units" the current balance represents, feeds the classic Balsara-style approximation RoR = ((1-E)/(1+E))^C that appears throughout trading risk literature. The risk unit itself - the money size of one bet in the formula - can be supplied directly as a percent of balance, or left at zero to derive it from the sample's own average loss, so the monitor can answer either "what is my risk of ruin at my historical average loss" or "what would it be if I risked X% per trade going forward". The formula assumes a stationary edge and independent trades, neither of which real trading strictly satisfies - a strategy's edge drifts, and consecutive trades are rarely perfectly independent. The result is presented, in the code, in the log and in this document, as a directional warning built from real history, not a guaranteed probability. Below the configured minimum sample size the panel reports insufficient data rather than a misleadingly precise-looking number from a handful of trades. Notes and limitations This is an approximation from a finite historical sample, not a certainty - a small or unrepresentative sample can produce a figure that looks safer or worse than the trader's true forward-looking risk. It only sees the trade history visible in this terminal's account; results will differ across accounts or after history is cleared. Treat a rising or high risk-of-ruin reading as a prompt to review sizing and edge, not as a literal probability of blowing the account.
Expert advisor · MT5 · v1.0 · Free
About Risk Of Ruin Monitor
Risk Of Ruin Monitor is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 7 settings, such as Lookback trades, Min trades required and Risk percent per trade. MQL source code included.
Files in the download: RiskOfRuinMonitor.ex5, RiskOfRuinMonitor.mq5, RiskOfRuinMonitor.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Lookback trades | 30 | Closed trades to sample, most recent first |
| Min trades required | 20 | Minimum sample size before a figure is trusted (else shown as insufficient data) |
| Risk percent per trade | 0.0 | Assumed forward risk % per trade; 0 = derive the risk unit from history's average loss |
| Warn threshold percent | 10.0 | Alert once risk of ruin reaches or exceeds this percent |
| Magic filter | -1 | Magic number filter (-1 = every magic number) |
| Current symbol only | false | Restrict the sample to this chart's symbol |
| Recalc seconds | 30 | Minimum seconds between recalculations, a ceiling on a cheap but non-zero cost |
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: Alerts · MT5 Expert Advisor · MQL5 Source Code