OPEN-SOURCE SCRIPT
Candle Streak Statistics

Candle Streak Statistics
What it does
This indicator counts every consecutive run of up-candles and down-candles in the chart's full history, then tells you how unusual the current run is compared to all the runs that came before it. Think of it as a "thermometer" that shows whether the market is in a perfectly normal streak or in territory it rarely visits.
Why it exists
I often ask myself: "Eight green candles in a row. Is that a lot?"
What you'll see
A compact stats table (position and size are configurable) showing, separately for up-streaks and down-streaks:
n: how many completed streaks were observed
Current run: length of the streak in progress
Pct rank: where the current run sits in the historical distribution (0% = shorter than everything, 100% = longest ever)
P(+1 more): historical probability that a streak which reached the current length extended by at least one more bar
Mean, Stdev, Median: central-tendency stats
p75 / p90 / p95: upper-percentile streak lengths
Mode: most common streak length (usually 1)
Optionally, a floating label above the last candle draws a 10-segment █/░ bar (the "thermometer" — for an at-a-glance read on rarity.)
How to read it
Pct rank ≥ 90% with low P(+1 more) → the current streak is in the rare-air zone and historically rarely extends further. Mean-reversion is statistically likely.
Pct rank mid-range with P(+1 more) ≥ 50% → nothing unusual; trend has room to continue.
Up vs. Down asymmetry → on equities, up-streaks typically have longer tails than down-streaks. Watching this gap shift can flag regime changes.
Design choices worth knowing
Doji handling: by default, exactly equal close == open bars are ignored (they don't break a streak). Adjustable via a tolerance input if you want to treat tiny-bodied candles the same way.
The live unfinished streak is excluded from the distribution by default. Including a still-in-progress run biases percentiles downward (it's censored data). A toggle lets you override.
Sample-size warning: if a direction has fewer than N completed streaks (default 20), its column gets a ⚠ marker. Don't trust statistics built on too little data.
Built on confirmed bars only. The distribution doesn't churn on every realtime tick.
Customization
Every visible element has a clearly labeled input: table position (9 anchor points), text size, all colors (text, neutral cell, up/down highlight, header), highlight transparency, and thermometer label colors. Defaults are tuned for light-themed charts.
Alerts
"Up streak ≥ p90": current up-run has entered the top 10% of history
"Down streak ≥ p90": current down-run has entered the top 10% of history
Best paired with
Any trend-following or stop-loss indicator. The combination of "my trailing stop says still hold" + "this streak is at p95 with a 15% continuation probability" is more informative than either signal alone. Use it as a sanity check on overextended moves.
Limitations
Streak-length distributions are roughly geometric. The mode is almost always 1, so I don't even know why I put it there. Don't lean on it.
Small samples (intraday timeframes on short chart histories) produce noisy upper-percentile estimates. Watch the n column.
Continuation probability is purely historical; it makes no claim about regime stability going forward. Statistics describe the past.
What it does
This indicator counts every consecutive run of up-candles and down-candles in the chart's full history, then tells you how unusual the current run is compared to all the runs that came before it. Think of it as a "thermometer" that shows whether the market is in a perfectly normal streak or in territory it rarely visits.
Why it exists
I often ask myself: "Eight green candles in a row. Is that a lot?"
What you'll see
A compact stats table (position and size are configurable) showing, separately for up-streaks and down-streaks:
n: how many completed streaks were observed
Current run: length of the streak in progress
Pct rank: where the current run sits in the historical distribution (0% = shorter than everything, 100% = longest ever)
P(+1 more): historical probability that a streak which reached the current length extended by at least one more bar
Mean, Stdev, Median: central-tendency stats
p75 / p90 / p95: upper-percentile streak lengths
Mode: most common streak length (usually 1)
Optionally, a floating label above the last candle draws a 10-segment █/░ bar (the "thermometer" — for an at-a-glance read on rarity.)
How to read it
Pct rank ≥ 90% with low P(+1 more) → the current streak is in the rare-air zone and historically rarely extends further. Mean-reversion is statistically likely.
Pct rank mid-range with P(+1 more) ≥ 50% → nothing unusual; trend has room to continue.
Up vs. Down asymmetry → on equities, up-streaks typically have longer tails than down-streaks. Watching this gap shift can flag regime changes.
Design choices worth knowing
Doji handling: by default, exactly equal close == open bars are ignored (they don't break a streak). Adjustable via a tolerance input if you want to treat tiny-bodied candles the same way.
The live unfinished streak is excluded from the distribution by default. Including a still-in-progress run biases percentiles downward (it's censored data). A toggle lets you override.
Sample-size warning: if a direction has fewer than N completed streaks (default 20), its column gets a ⚠ marker. Don't trust statistics built on too little data.
Built on confirmed bars only. The distribution doesn't churn on every realtime tick.
Customization
Every visible element has a clearly labeled input: table position (9 anchor points), text size, all colors (text, neutral cell, up/down highlight, header), highlight transparency, and thermometer label colors. Defaults are tuned for light-themed charts.
Alerts
"Up streak ≥ p90": current up-run has entered the top 10% of history
"Down streak ≥ p90": current down-run has entered the top 10% of history
Best paired with
Any trend-following or stop-loss indicator. The combination of "my trailing stop says still hold" + "this streak is at p95 with a 15% continuation probability" is more informative than either signal alone. Use it as a sanity check on overextended moves.
Limitations
Streak-length distributions are roughly geometric. The mode is almost always 1, so I don't even know why I put it there. Don't lean on it.
Small samples (intraday timeframes on short chart histories) produce noisy upper-percentile estimates. Watch the n column.
Continuation probability is purely historical; it makes no claim about regime stability going forward. Statistics describe the past.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.