Win/loss streak analysis
Walks the trade history to measure the longest winning streak, the longest losing streak and the current run, then derives a sizing recommendation — the statistical foundation of money management that survives.
Prerequisites
MetaTrader 5, MQL5
MQL5
void StreakAnalysis(int days)
{
if(!HistorySelect(TimeCurrent() - days * 86400, TimeCurrent()))
return;
int curWin = 0, curLoss = 0, maxWin = 0, maxLoss = 0, n = 0;
for(int i = 0; i < HistoryDealsTotal(); i++)
{
ulong d = HistoryDealGetTicket(i);
if(HistoryDealGetInteger(d, DEAL_ENTRY) != DEAL_ENTRY_OUT)
continue;
n++;
if(HistoryDealGetDouble(d, DEAL_PROFIT) >= 0)
{
curWin++; curLoss = 0;
maxWin = MathMax(maxWin, curWin);
}
else
{
curLoss++; curWin = 0;
maxLoss = MathMax(maxLoss, curLoss);
}
}
PrintFormat("=== SERIES DE GAINS / PERTES (%d jours, %d trades) ===", days, n);
PrintFormat("Plus longue série gagnante : %d trades", maxWin);
PrintFormat("Plus longue série perdante : %d trades", maxLoss);
PrintFormat("Série en cours : %s",
curWin > 0 ? StringFormat("%d gain(s) consécutif(s)", curWin)
: StringFormat("%d perte(s) consécutive(s)", curLoss));
PrintFormat("Sizing conseillé : budgéter au moins %d pertes d'affilée", maxLoss + 2);
}Result
2026.06.10 22:12:02.731 StreakStats (EURUSD,H1) === SERIES DE GAINS / PERTES (90 jours, 124 trades) === 2026.06.10 22:12:02.732 StreakStats (EURUSD,H1) Plus longue série gagnante : 7 trades 2026.06.10 22:12:02.732 StreakStats (EURUSD,H1) Plus longue série perdante : 5 trades 2026.06.10 22:12:02.733 StreakStats (EURUSD,H1) Série en cours : 2 perte(s) consécutive(s) 2026.06.10 22:12:02.733 StreakStats (EURUSD,H1) Sizing conseillé : budgéter au moins 7 pertes d'affilée
StreaksStatistiquesMoney ManagementDrawdown