Loading…

Consecutive Win Loss Streak Report

A streak is a simple idea - how many wins or losses in a row - but it is easy to get wrong in MQL4, and the failure is silent rather than a crash. The trap is history order. OrdersHistoryTotal() and OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) hand back closed trades in whatever order the terminal happens to hold them in, which is not guaranteed to be the order the trades actually closed in. It is often close, which is exactly what makes the bug dangerous: a script that skips the sort will look right on most accounts, most of the time, and then quietly misreport a streak the one time history arrived out of order - after a history import, after a broker migration, or simply because of how the terminal cached older tickets. This script collects ticket, close time and net profit for every closed market trade first, then explicitly sorts that list by close time before any streak counting begins. The sort is a small insertion sort, which is the right tool here: account history for the kind of manual or swing trading this report is meant for is small, and the list is usually close to already sorted, so simplicity wins over an asymptotically faster algorithm that this script would only run once per click anyway. The second decision is what to do with a breakeven trade - net profit, after swap and commission, of exactly zero. A breakeven is not a win and not a loss, so it does not fit cleanly into a streak of either. Rather than picking a silent default, this is exposed as InpBreakevenMode with three settings: treat it as a win, treat it as a loss, or treat it as a breaker that ends whatever streak was running and starts the next streak fresh from the following trade. The breaker option is the default, because it is the only one of the three that does not put a thumb on the scale - counting a breakeven as a win flatters the win streak, counting it as a loss flatters the loss streak, and a trader reading the report should be able to trust that a long streak is genuinely a long run of one outcome rather than one outcome plus a zero-money trade that got counted its way. Net profit is the sum of OrderProfit(), OrderSwap() and OrderCommission(), matching the actual account-balance effect of the trade rather than the raw price result alone. Comparing that sum to zero with ordinary double equality is safe here: it is a sum of figures the broker has already rounded to the account currency, not an accumulated floating-point calculation, so there is no rounding drift to worry about. Notes and limitations - Streaks are defined on money (net profit after swap and commission), not on R-multiples, lot-adjusted results, or any other normalisation. A streak of five wins built from small lots and a streak of five wins built from large lots look identical in this report; only the cumulative net figure hints at the difference. - History depth is whatever the terminal currently has loaded or downloaded for this account. If older history has not been fetched from the broker, streaks that happened before the loaded window are invisible to the script and will not appear in the totals or the distribution tables. - Only market trades count. OP_BUY and OP_SELL entries are read; balance and credit lines in the same history pool, and any pending-order entries, are filtered out before the streak logic ever sees them. - The report is a point-in-time read. It does not update live and does not need to - re-run the script after new trades close to refresh it. - No CSV or file output is produced. The report is Experts-log and Alert only, by design, to keep this submission focused on the streak logic.

Script · MT5 · v1.0 · Free

About Consecutive Win Loss Streak Report

Consecutive Win Loss Streak Report is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 1 setting, such as Breakeven mode. MQL source code included.

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

Settings

SettingDefaultWhat it does
Breakeven modeBE_BREAKERHow a net-zero (breakeven) trade affects a streak

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 · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria