ProRealTime ProBuilder Close-to-Close Streak Indicator: Count Consecutive Rising and Falling Closes
Beginner Trading Tutorial | ProRealTime | ProBuilder custom indicator
When a market closes higher for several consecutive bars, traders often describe it as a winning streak for buyers. But a chart can make it difficult to count exactly how long the sequence has lasted, particularly when unchanged prices or small countertrend movements occur. A signed streak indicator translates that observation into a simple integer that can be reproduced directly from closing prices.
In this tutorial we develop a complete ProBuilder indicator for ProRealTime that counts consecutive higher or lower closes. The indicator restarts the count when direction changes and resets it to zero when two adjacent closes are identical. We also separate the calculation of the streak from its display, so a user can inspect either a previously completed bar or the developing bar. The example introduces one of ProBuilder's most useful concepts: the historical value of an ordinary variable.
1. The definition: direction and duration, not magnitude
Let C(t) be the closing price of bar t and S(t) its signed streak. When C(t) exceeds C(t−1), the streak is S(t−1)+1 if the previous count is positive; otherwise the new count is +1. When C(t) is lower, the count is S(t−1)−1 if the previous count is negative; otherwise it becomes −1. Equal closes set the count to zero. The first available bar is seeded with zero because it has no preceding comparison in the loaded dataset.
This definition measures close-to-close direction rather than whether the current candle closes above its own open. A bullish candle body after a large gap down may still represent a lower close than the previous bar. Likewise, a bearish candle body may finish above the preceding close. A streak based on candle body direction would be a different indicator.

| Close | Comparison | Unshifted streak |
|---|---|---|
| 100 | Initial bar | 0 |
| 101 | Higher | 1 |
| 103 | Higher | 2 |
| 102 | Lower | −1 |
| 101 | Lower | −2 |
| 101 | Equal | 0 |
| 104 | Higher | 1 |
All prices are hypothetical. Notice that the rise from 101 to 103 adds exactly one count, even though it is larger than the rise from 100 to 101. The indicator does not weight the count by the size of each move. Its purpose is to describe the length of the current uninterrupted sequence. It is not a fixed-window percentage of rising bars and it is not a cumulative price return.
2. Complete ProBuilder indicator
// PatternSmart Close-to-Close Streak
// ProRealTime ProBuilder custom indicator
// Set to 1 for a prior completed bar reading.
// Set to 0 for the current bar, including live preview.
confirmedOnly = 1
// Seed the first available bar without reading missing history.
IF BarIndex = 0 THEN
streak = 0
ELSE
// Always use the preceding bar's count, not the
// previous intrabar execution's current value.
IF Close > Close[1] THEN
IF streak[1] > 0 THEN
streak = streak[1] + 1
ELSE
streak = 1
ENDIF
ELSIF Close < Close[1] THEN
IF streak[1] < 0 THEN
streak = streak[1] - 1
ELSE
streak = -1
ENDIF
ELSE
// A tie interrupts either direction.
streak = 0
ENDIF
ENDIF
// In confirmed mode, display the previous bar's count.
displayed = streak
IF confirmedOnly = 1 THEN
IF BarIndex > 0 THEN
displayed = streak[1]
ELSE
displayed = 0
ENDIF
ENDIF
RETURN displayed AS "Streak", 0 AS "Zero"
3. Understand the recursive calculation
The official ProBuilder programming guide explains that a normal indicator variable retains a bar-indexed history, which can be accessed with square brackets. The expression streak[1] therefore retrieves the count calculated for the preceding bar. Close[1] similarly retrieves the previous closing price. BarIndex starts at zero for the first bar in the calculation history, allowing the script to seed the state before using historical references.
At every subsequent bar, the code selects one of three mutually exclusive branches: higher, lower or unchanged. A positive count can grow only when another higher close occurs. A negative count can become more negative only after another lower close. When direction changes, the count starts at one in the new direction rather than adding or subtracting one from the previous opposite-signed value. This distinction is essential. Simply subtracting one from a positive count on a down bar would describe a cumulative balance instead of a consecutive streak.
Using the previous bar's value also makes the calculation independent of the number of intrabar executions. In the live indicator, a tick can trigger another calculation for the same bar. The expression streak[1]+1 refers to the earlier bar, so successive updates do not accidentally increment the count multiple times within one candle. For example, if the prior streak is +3, ten updates that keep the current price above the previous close all imply a provisional streak of +4, not +13.
4. Completed-bar mode and alignment
| Source setting | Display behavior |
|---|---|
| confirmedOnly = 1 (default) | Previous completed bar's count, shown one bar later |
| confirmedOnly = 0 | Current bar's count, including a changing live value |
The default uses streak[1] for display. This makes the latest plotted value available from a preceding completed candle, without using the developing bar's close. The trade-off is an intentional one-bar displacement: on the bar where the example closes at 103, confirmed mode displays +1, corresponding to the earlier close of 101. The +2 result becomes visible on the next bar. The first bar's zero is an initialization value rather than an observed comparison. In live mode the output is aligned with the evaluated bar, and the latest observation may change until the bar finishes.
Neither mode uses future data. However, a chart that receives corrected historical prices or loads a longer price history can reconstruct a different earlier streak. A sequence already in progress at the left edge of the dataset cannot be fully counted unless the earlier observations are available. For long-running streaks, load enough chart history to include the last direction change or tie.
5. Installation and validation
- Open a standard candlestick chart in ProRealTime and enter the Indicators area.
- Create a custom indicator using ProBuilder, name it PS Close-to-Close Streak and paste the complete source.
- Apply it to a new panel. Review any syntax diagnostics before relying on the display.
- Leave confirmedOnly at 1 for a prior-bar reading. To examine aligned historical counts, edit that source setting to 0 and reapply the indicator.
- Choose consecutive completed bars and manually compare their closes. Start at a tie or reversal, follow the sequence and compare the resulting signed integers.
Verify four cases: an extending up run, an extending down run, a reversal and an unchanged close. Then examine a live candle that moves across its prior close. In preview mode, the latest value should change according to the comparison, without accumulating a count on every tick. In confirmed mode, the value should remain tied to the preceding completed bar. Finally, compare the first few plotted bars after changing the amount of loaded history to understand the initialization boundary.
6. Use the information in context
Streak length can describe recent persistence or provide an input to a research filter. A reading of +6 does not prove that the next bar will rise or that the trend is exhausted. The size of price movements, liquidity, spread, broader trend structure and session boundaries are separate considerations. On a one-minute chart, six comparisons cover six bar-to-bar intervals, whereas on a daily chart they cover six trading-bar intervals. The script does not reset at a new day or session unless an actual tie or reversal occurs. Synthetic chart types may use constructed closes, so use conventional candles when researching recorded market closes.
If you would like to extend this free program with session resets, minimum price-change filters, custom alerts or strategy integration, contact us through our Custom Trading Software Development Services.
The implementation was checked against the official ProBuilder language guide but has not been compiled or executed in ProRealTime. Verify it in your own installation. Trading involves risk, and streak length alone cannot guarantee future price movement or profitability.