Discussing the article: "Survival Analysis for Trade Exits: A Discrete-Time Competing-Risks Model in MQL5"

Check out the new article: Survival Analysis for Trade Exits: A Discrete-Time Competing-Risks Model in MQL5.

Fixed exits ignore state changes while a trade is open. We implement a discrete-time competing-risks model entirely in MQL5, estimate cause-specific hazards for take-profit and stop-loss via Newton–Raphson on a person-period dataset with time-varying features, and turn cumulative incidence into a bar-by-bar hold-or-close rule, then test it against fixed take-profit/stop-loss with identical entry logic.

Most of the effort in a trading system goes into the entry. We optimise the filter, tune the lookback, argue about confirmation. Then we bolt on a two-to-one take-profit and a one-ATR stop and stop thinking about it. That fixed exit throws away everything the market tells us after we are in the trade.

Think about what happens once a position is open. It runs one and a half R in your favour and stalls. Volatility doubles. Price falls back through the moving average it broke out from. Each of those facts changes the probability of hitting the target before the stop. A fixed exit ignores them.

Medical statistics solved a version of this decades ago. A live position is a patient under observation. Each bar it survives is one more period at risk, leaving the study one of two mutually exclusive ways: take-profit fires, or stop-loss fires. Those are competing risks — one happening permanently prevents the other. If the time stop arrives first, the observation is censored.

That framing fixes two things a naive "will this trade win?" classifier gets wrong. A trade still open at the time stop is a censored observation, not a failed prediction. And trade state is not static — MFE, MAE, distance to each barrier and the volatility regime all move while the position lives. A discrete-time hazard model eats time-varying covariates naturally; a classifier scored once at entry cannot.

What follows is a complete native MQL5 implementation. It uses no DLLs, no ONNX runtime, and no ALGLIB. We harvest a person-period table and fit two cause-specific hazards by penalised maximum likelihood. We then convert cumulative incidence into a bar-by-bar hold-or-close decision. The result is tested against fixed exits on four instruments with every parameter identical, and reported including the parts that performed poorly.

Author: Adewumi Babatunde Gbadebo