All free tools

Trading metric

Consecutive Loss Streak Calculator

Enter a win rate, a number of trades, and a losing streak length to see how likely at least one run of that many losses in a row is, assuming each trade is independent.

Chance of at least one streak
64.68%
Across the whole sample of trades.
Average trades until the first streak
96.7
The average wait before the first run of this length begins to complete.
Next trades all lose
1.845%
The chance the next run of that many trades are all losses.

What this calculates

If each trade loses with probability q, independently of the others, the chance that the next k trades all lose is q to the power k. The chance of a run of k losses appearing at some point in a longer sample of n trades is larger, because a run can start at many different trades. This tool tracks the length of the current losing run trade by trade to get that probability exactly.

The average number of trades until the first run of k losses is the sum of 1/q, 1/q squared, up to 1/q to the power k (Feller, An Introduction to Probability Theory and Its Applications). For a fair coin and a run of two, that is 6 flips.

Limits of the model

Real trade results are often not independent, and a win rate measured on a small sample carries its own uncertainty. Treat the output as arithmetic on the numbers you entered, not a description of what any strategy will do. Longer losing runs than a simple model suggests are a reason to look at your own trade list, not a forecast.

What are TradingView and Pine Script?

TradingView is one of the most widely used charting and market-analysis platforms, where traders and analysts study price movement across stocks, crypto, forex, and futures on interactive charts. Pine Script is TradingView's own lightweight programming language, created so anyone can build custom tools that run directly on those charts.

People use Pine Script to build four main kinds of tools. Indicators calculate and plot values on the chart, exactly like the calculation above, but recomputed automatically on every bar. Strategies add explicit entry and exit rules and can be backtested against historical data in TradingView's Strategy Tester to see how they would have behaved. Screeners scan many symbols at once for conditions you define. Alerts notify you the moment a condition you specified occurs, so you do not have to watch the screen.

The value is precision and automation. Instead of eyeballing a chart, you describe exactly what you want measured, visualized, or notified about, and TradingView runs it consistently across any market and timeframe. That is why traders, analysts, and developers write Pine Script: it turns a manual charting idea into a repeatable tool. These tools are for tracking, visualizing, and testing market ideas; they do not tell you what to trade, and that decision always remains yours.

Writing that code by hand means learning Pine Script's syntax, its type system, and the exact names of hundreds of built-in functions. It is a real programming language, and small mistakes stop a script from compiling in the Pine Editor.

Turn this into Pine Script

This calculator uses a win rate you type in. A Pine Script strategy can count the actual losing streak across its closed trades and raise an alert when the streak reaches a length you choose. The script uses strategy.closedtrades.profit() to check each closed trade once and resets the counter on the next winner.

Pine Script v6
//@version=6
strategy("Consecutive Loss Counter", overlay=true)

alertStreak = input.int(5, "Losing streak to flag", minval=1)

// Placeholder entry rules: replace with your own
fast = ta.sma(close, 10)
slow = ta.sma(close, 30)
if ta.crossover(fast, slow)
    strategy.entry("Long", strategy.long)
if ta.crossunder(fast, slow)
    strategy.close("Long")

// Track the current run of losing closed trades
var int lossStreak = 0
var int seenTrades = 0
if strategy.closedtrades > seenTrades
    for i = seenTrades to strategy.closedtrades - 1
        if strategy.closedtrades.profit(i) < 0
            lossStreak += 1
        else
            lossStreak := 0
    seenTrades := strategy.closedtrades

if lossStreak >= alertStreak and barstate.isconfirmed
    alert("Losing streak of " + str.tostring(lossStreak) + " trades", alert.freq_once_per_bar)

plot(lossStreak, "Current losing streak", color=color.red)

PineScripter is an AI built specifically for Pine Script. You describe what you want in plain English and it writes TradingView-ready v6 code. Because it is specialized on the Pine Script language and its exact function signatures, it tends to produce code that compiles far more reliably than general-purpose models like ChatGPT, which often invent functions that do not exist in Pine Script.

Related free calculators

From the blog

PineScripter is an AI developer tool that helps you write Pine Script code. It is not a financial advisor and will never offer financial, investment, or trading advice. Everything on this page, including the calculator and the explanations, is provided purely for educational and informational purposes. Any decision about how to interpret an indicator or trade a market is entirely your own. See our full disclaimer for more.