A trader shows a 71% win rate. It sounds safe. But a win rate says nothing about how deep the bad runs were, or how long they lasted. Seven losses in a row, most of them larger than any win, can erase a month of small gains.
This post builds the two numbers that answer that: max drawdown and the longest losing streak. It is about 120 lines of TypeScript, with no library, and it works on any list of closed trades.
Disclosure: I am the founder of copy.top. copy.top is independent and not affiliated with pump.fun or fomo.
Why a losing run matters more than a losing trade
If you copy a trader with a fixed size, you do not live through one trade at a time. You live through a sequence. What decides whether your account survives is the worst sequence, not the worst single trade. This is the reason the fixed-size approach in copy trading strategies needs a size chosen against the losing run, not against the average trade.
The sample data below is made up. It looks like a memecoin trader: many small wins, a few large losses, and one clear bad week. It is not a real person.
Setup
The files are TypeScript and run on Node 22.6 or newer with type stripping (tested here on Node 24.7):
node --experimental-strip-types run.ts Imports between files need the .ts extension, and types use import type, which this mode requires. For plain JavaScript, rename to .mjs, delete the annotations and the import type lines.
Types
A closed trade is two fields: when it closed and how many dollars it made or lost.
// types.ts export interface ClosedTrade { closedAt: string; // ISO 8601 date-time pnlUsd: number; // realized profit or loss in dollars } export interface EquityPoint { label: string; // "start" or the close date of the trade equity: number; } export interface Drawdown { maxDrawdownUsd: number; maxDrawdownPct: number; // of the peak, 0 to 100 peakLabel: string; troughLabel: string; peakEquity: number; troughEquity: number; } export interface LosingStreak { length: number; totalLossUsd: number; from: string; to: string; } The sample trades
Forty-one closed trades over about five weeks. The wins are small and frequent. The losses are rarer and larger. From 2026-09-17 to 2026-09-23 there is a run of seven losses in a row.
// trades.ts // A made-up sample of 41 closed trades. Not a real trader. import type { ClosedTrade } from "./types.ts"; export const trades: ClosedTrade[] = [ { closedAt: "2026-09-01T08:12:00Z", pnlUsd: 85 }, { closedAt: "2026-09-01T14:40:00Z", pnlUsd: 42 }, { closedAt: "2026-09-02T09:05:00Z", pnlUsd: -60 }, { closedAt: "2026-09-02T19:31:00Z", pnlUsd: 120 }, { closedAt: "2026-09-03T11:18:00Z", pnlUsd: 64 }, { closedAt: "2026-09-04T07:55:00Z", pnlUsd: 38 }, { closedAt: "2026-09-04T16:22:00Z", pnlUsd: 95 }, { closedAt: "2026-09-05T10:47:00Z", pnlUsd: -140 }, { closedAt: "2026-09-06T13:09:00Z", pnlUsd: 72 }, { closedAt: "2026-09-07T08:34:00Z", pnlUsd: 55 }, { closedAt: "2026-09-07T21:03:00Z", pnlUsd: 110 }, { closedAt: "2026-09-08T12:26:00Z", pnlUsd: 48 }, { closedAt: "2026-09-09T09:50:00Z", pnlUsd: 130 }, { closedAt: "2026-09-10T15:15:00Z", pnlUsd: 33 }, { closedAt: "2026-09-11T11:41:00Z", pnlUsd: -75 }, { closedAt: "2026-09-12T08:02:00Z", pnlUsd: 90 }, { closedAt: "2026-09-13T17:28:00Z", pnlUsd: 61 }, { closedAt: "2026-09-14T10:37:00Z", pnlUsd: 145 }, { closedAt: "2026-09-15T13:54:00Z", pnlUsd: 52 }, { closedAt: "2026-09-16T09:19:00Z", pnlUsd: 78 }, { closedAt: "2026-09-17T14:06:00Z", pnlUsd: -230 }, { closedAt: "2026-09-18T10:23:00Z", pnlUsd: -310 }, { closedAt: "2026-09-19T16:48:00Z", pnlUsd: -95 }, { closedAt: "2026-09-20T08:31:00Z", pnlUsd: -420 }, { closedAt: "2026-09-21T12:57:00Z", pnlUsd: -180 }, { closedAt: "2026-09-22T19:14:00Z", pnlUsd: -260 }, { closedAt: "2026-09-23T09:42:00Z", pnlUsd: -150 }, { closedAt: "2026-09-24T11:08:00Z", pnlUsd: 98 }, { closedAt: "2026-09-25T15:36:00Z", pnlUsd: 67 }, { closedAt: "2026-09-26T08:45:00Z", pnlUsd: 115 }, { closedAt: "2026-09-27T13:20:00Z", pnlUsd: 44 }, { closedAt: "2026-09-28T10:11:00Z", pnlUsd: 82 }, { closedAt: "2026-09-29T17:39:00Z", pnlUsd: -85 }, { closedAt: "2026-09-30T09:27:00Z", pnlUsd: 126 }, { closedAt: "2026-10-01T14:52:00Z", pnlUsd: 59 }, { closedAt: "2026-10-02T11:16:00Z", pnlUsd: 101 }, { closedAt: "2026-10-03T08:38:00Z", pnlUsd: 37 }, { closedAt: "2026-10-04T16:04:00Z", pnlUsd: 140 }, { closedAt: "2026-10-05T12:33:00Z", pnlUsd: -110 }, { closedAt: "2026-10-06T09:59:00Z", pnlUsd: 76 }, { closedAt: "2026-10-07T15:21:00Z", pnlUsd: 88 }, ]; The statistics
Everything is a pure function: same input, same output, no clock, no network.
The equity curve starts at a balance and adds each trade in close order. Max drawdown walks that curve, remembers the highest point so far, and measures how far each later point falls below it. The biggest fall wins. The result keeps the peak and the trough so you can see when it happened, and the percent is taken from the peak.
The losing streak counts consecutive trades with a pnl below zero. A trade at exactly zero ends the streak. The function returns the length, the dates and the total loss of the longest one.
// stats.ts import type { ClosedTrade, EquityPoint, Drawdown, LosingStreak } from "./types.ts"; const day = (iso: string) => iso.slice(0, 10); // Sort by close time so the order never depends on how the list was built. export function sortTrades(trades: ClosedTrade[]): ClosedTrade[] { return [...trades].sort((a, b) => a.closedAt.localeCompare(b.closedAt)); } export function equityCurve(trades: ClosedTrade[], startBalance: number): EquityPoint[] { const curve: EquityPoint[] = [{ label: "start", equity: startBalance }]; let equity = startBalance; for (const t of sortTrades(trades)) { equity += t.pnlUsd; curve.push({ label: day(t.closedAt), equity }); } return curve; } export function maxDrawdown(curve: EquityPoint[]): Drawdown { let peak = curve[0]; let best = { usd: 0, pct: 0, peak: curve[0], trough: curve[0] }; for (const p of curve) { if (p.equity > peak.equity) peak = p; const usd = peak.equity - p.equity; if (usd > best.usd) { best = { usd, pct: (usd / peak.equity) * 100, peak, trough: p }; } } return { maxDrawdownUsd: best.usd, maxDrawdownPct: best.pct, peakLabel: best.peak.label, troughLabel: best.trough.label, peakEquity: best.peak.equity, troughEquity: best.trough.equity, }; } // A losing trade is pnl below zero. A break-even trade ends the streak. export function longestLosingStreak(trades: ClosedTrade[]): LosingStreak { const sorted = sortTrades(trades); let best: LosingStreak = { length: 0, totalLossUsd: 0, from: "", to: "" }; let cur: LosingStreak = { length: 0, totalLossUsd: 0, from: "", to: "" }; for (const t of sorted) { if (t.pnlUsd < 0) { if (cur.length === 0) cur = { length: 0, totalLossUsd: 0, from: day(t.closedAt), to: "" }; cur.length += 1; cur.totalLossUsd += t.pnlUsd; cur.to = day(t.closedAt); if (cur.length > best.length) best = { ...cur }; } else { cur = { length: 0, totalLossUsd: 0, from: "", to: "" }; } } return best; } export function winRate(trades: ClosedTrade[]): number { if (trades.length === 0) return 0; return trades.filter((t) => t.pnlUsd > 0).length / trades.length; } export function averageWin(trades: ClosedTrade[]): number { const w = trades.filter((t) => t.pnlUsd > 0); return w.length ? w.reduce((s, t) => s + t.pnlUsd, 0) / w.length : 0; } // Returned as a negative number. export function averageLoss(trades: ClosedTrade[]): number { const l = trades.filter((t) => t.pnlUsd < 0); return l.length ? l.reduce((s, t) => s + t.pnlUsd, 0) / l.length : 0; } // Gross profit divided by gross loss. Infinity when there are no losses. export function profitFactor(trades: ClosedTrade[]): number { const gain = trades.filter((t) => t.pnlUsd > 0).reduce((s, t) => s + t.pnlUsd, 0); const loss = -trades.filter((t) => t.pnlUsd < 0).reduce((s, t) => s + t.pnlUsd, 0); return loss === 0 ? Infinity : gain / loss; } // Scale of the trader's size (1 = same size) that keeps // budget - scale * streakLoss at or above the floor. export function maxCopyScale(budget: number, floor: number, streakLossUsd: number): number { const loss = Math.abs(streakLossUsd); if (loss === 0) return Infinity; return Math.max(0, (budget - floor) / loss); } The last function, maxCopyScale, is explained in the sizing section further down.
The runner
It prints a short summary, then a small table with the five worst trades, then three sizing examples. The starting balance of 5,000 is only the base for the equity curve, so the percentage has something to work against.
// run.ts import { trades } from "./trades.ts"; import { equityCurve, maxDrawdown, longestLosingStreak, winRate, averageWin, averageLoss, profitFactor, maxCopyScale, } from "./stats.ts"; const START = 5000; const usd = (n: number) => `${n < 0 ? "-" : ""}$${Math.abs(Math.round(n)).toLocaleString("en-US")}`; const curve = equityCurve(trades, START); const dd = maxDrawdown(curve); const streak = longestLosingStreak(trades); const total = trades.reduce((s, t) => s + t.pnlUsd, 0); console.log(`trades: ${trades.length}, net pnl: ${usd(total)}`); console.log(`win rate: ${Math.round(winRate(trades) * 100)}%`); console.log(`average win: ${usd(averageWin(trades))}, average loss: ${usd(averageLoss(trades))}`); console.log(`profit factor: ${profitFactor(trades).toFixed(2)}`); console.log( `max drawdown: ${usd(dd.maxDrawdownUsd)} (${dd.maxDrawdownPct.toFixed(1)}%), ` + `peak ${dd.peakLabel} at ${usd(dd.peakEquity)}, trough ${dd.troughLabel} at ${usd(dd.troughEquity)}`, ); console.log( `longest losing streak: ${streak.length} trades, ${usd(streak.totalLossUsd)}, ${streak.from} to ${streak.to}`, ); console.log("\n5 worst trades"); console.table( [...trades] .sort((a, b) => a.pnlUsd - b.pnlUsd) .slice(0, 5) .map((t) => ({ closed: t.closedAt.slice(0, 10), pnl_usd: t.pnlUsd })), ); console.log("\nsizing for the losing run"); const examples = [ { budget: 1000, floor: 800 }, { budget: 1000, floor: 500 }, { budget: 3000, floor: 2400 }, ]; for (const e of examples) { const s = maxCopyScale(e.budget, e.floor, streak.totalLossUsd); console.log( `budget ${usd(e.budget)}, floor ${usd(e.floor)}: copy at ${(s * 100).toFixed(1)}% of the trader's size`, ); } Output
Exactly as printed:
trades: 41, net pnl: $236 win rate: 71% average win: $81, average loss: -$176 profit factor: 1.11 max drawdown: $1,645 (27.2%), peak 2026-09-16 at $6,043, trough 2026-09-23 at $4,398 longest losing streak: 7 trades, -$1,645, 2026-09-17 to 2026-09-23 5 worst trades ┌─────────┬──────────────┬─────────┐ │ (...
