Survival analysis applied to MetaTrader 5 deal history: Kaplan-Meier and hazard curves that answer how long a trade lasts and when it is most likely to die, not just how often it wins.
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-08-14 00:09:54 +00:00
Experts/Survival initial commit 2026-08-08 12:28:27 +00:00
Include/Survival initial commit 2026-08-08 12:27:33 +00:00
Indicators/Survival initial commit 2026-08-08 12:28:05 +00:00
README.md Add README 2026-08-14 00:09:54 +00:00

Survival

Survival analysis over your own MetaTrader 5 deal history. Answers how long trades last and when they are most likely to die, which a win rate cannot tell you.

Companion code for the MQL5 article: https://www.mql5.com/en/articles/23928

What it does

A win rate collapses a trade's whole life into one bit. It cannot say whether losers die early or bleed out slowly, whether an edge decays after a certain holding time, or whether a stop is sitting in the worst possible place.

Survival analysis is built for exactly that question, and it handles censoring, which is the part naive approaches get wrong. A trade still open when the history ends has not "not failed". It is censored, and dropping it or counting it as a survivor both bias the result.

The engine reads deal history into observations, then produces the Kaplan-Meier survival curve, the hazard rate and the cumulative hazard from a single sweep. SurvivalPanel.mq5 draws them.

The article covers the edge cases, which is where this kind of analysis usually goes wrong: partial closes, hedged positions and thin samples.

Layout

Include/Survival/SurvivalTypes.mqh   shared types
Include/Survival/TradeHistory.mqh    deal history into observations
Include/Survival/SurvivalCore.mqh    Kaplan-Meier, hazard, cumulative hazard
Indicators/Survival/SurvivalPanel.mq5  the panel
Experts/Survival/SurvivalDemo.mq5    demonstration expert

The panel reads your account's own history, so it needs deals to be present before it shows anything.

Disclaimer

Educational code. Past behaviour of any model or dataset says nothing about future results. Test on your own data and broker conditions before drawing conclusions.