Indicators··7 min read

Consecutive Close Counter

0 references, link-verified · inline [n] markersEditor of record: Shane CantyStandards review editorial standard · audit log

The Consecutive Close Counter tracks streaks of consecutive rising and falling closes and displays cumulative streak counts with summary statistics. Traders use this indicator to identify momentum phases, confirm price continuity, and quantify the duration and frequency of directional runs without requiring additional oscillators or comparative logic. It appears as a histogram on a separate pane alongside a statistics table updated each bar.

//@version=6
indicator("Consecutive Close Counter", overlay=false, max_bars_back=500)

// User inputs
show_table = input(true, "Show Statistics Table")
table_pos = input.string("top-right", "Table Position",
    options=["top-left", "top-right", "bottom-left", "bottom-right"])

// Persistent variables for streak tracking
var int current_streak = 0
var int longest_up_streak = 0
var int longest_down_streak = 0
var int up_streaks_ended = 0
var int down_streaks_ended = 0

// Close direction detection
is_up = close > close[1]
is_down = close < close[1]

// Streak logic: up closes increment, down closes decrement
// Flat closes (open = close, gap open) continue current streak
if is_up
    if current_streak >= 0
        current_streak += 1
    else
        // Flip from down to up: record down streak, start up
        down_len = -current_streak
        if down_len > longest_down_streak
            longest_down_streak := down_len
        down_streaks_ended += 1
        current_streak := 1
    
    if current_streak > longest_up_streak
        longest_up_streak := current_streak

else if is_down
    if current_streak <= 0
        current_streak -= 1
    else
        // Flip from up to down: record up streak, start down
        up_len = current_streak
        if up_len > longest_up_streak
            longest_up_streak := up_len
        up_streaks_ended += 1
        current_streak := -1
    
    if -current_streak > longest_down_streak
        longest_down_streak := -current_streak

// Plot current streak as column chart
bar_color = current_streak > 0 ? color.new(color.green, 20) :
            current_streak < 0 ? color.new(color.red, 20) : color.gray
plot(current_streak, title="Close Streak", color=bar_color, 
     style=plot.style_columns, linewidth=2)
hline(0, color=color.gray, linestyle=hline.style_dashed, linewidth=1)

// Statistics table
if show_table
    var table tb = na
    
    if na(tb)
        pos = switch table_pos
            "top-left" => position.top_left
            "top-right" => position.top_right
            "bottom-left" => position.bottom_left
            => position.bottom_right
        tb := table.new(pos, 7, 2, border_color=color.orange, border_width=2)
    
    // Header row
    table.cell(tb, 0, 0, "Metric", text_color=color.white, bgcolor=color.navy, text_size=size.small)
    table.cell(tb, 0, 1, "Value", text_color=color.white, bgcolor=color.navy, text_size=size.small)
    
    // Current streak with live color
    curr_color = current_streak > 0 ? color.green : current_streak < 0 ? color.red : color.gray
    table.cell(tb, 1, 0, "Active Streak", text_color=color.white, bgcolor=color.gray, text_size=size.small)
    table.cell(tb, 1, 1, str.tostring(current_streak), text_color=color.white, bgcolor=curr_color, text_size=size.small)
    
    // Longest streaks
    table.cell(tb, 2, 0, "Longest Up", text_color=color.white, bgcolor=color.gray, text_size=size.small)
    table.cell(tb, 2, 1, str.tostring(longest_up_streak), text_color=color.white, bgcolor=color.green, text_size=size.small)
    
    table.cell(tb, 3, 0, "Longest Down", text_color=color.white, bgcolor=color.gray, text_size=size.small)
    table.cell(tb, 3, 1, str.tostring(longest_down_streak), text_color=color.white, bgcolor=color.red, text_size=size.small)
    
    // Streak counts (cumulative completed streaks)
    table.cell(tb, 4, 0, "Up Streaks Ended", text_color=color.white, bgcolor=color.gray, text_size=size.small)
    table.cell(tb, 4, 1, str.tostring(up_streaks_ended), text_color=color.white, bgcolor=color.gray, text_size=size.small)
    
    table.cell(tb, 5, 0, "Down Streaks Ended", text_color=color.white, bgcolor=color.gray, text_size=size.small)
    table.cell(tb, 5, 1, str.tostring(down_streaks_ended), text_color=color.white, bgcolor=color.gray, text_size=size.small)
    
    // Up percentage
    total_completed = up_streaks_ended + down_streaks_ended
    up_pct = total_completed > 0 ? math.round(100.0 * up_streaks_ended / total_completed, 1) : 0
    table.cell(tb, 6, 0, "Up Streak %", text_color=color.white, bgcolor=color.gray, text_size=size.small)
    table.cell(tb, 6, 1, str.tostring(up_pct) + "%", text_color=color.white, bgcolor=color.gray, text_size=size.small)

How the code works

The indicator maintains a signed integer counter (current_streak) that increments by one for each consecutive close above the prior close and decrements by one for each consecutive close below the prior close. A close equal to the prior close (gap open or flat) continues the existing streak without change.

When the direction reverses (from positive to negative or vice versa), the indicator records the completed streak length in longest_up_streak or longest_down_streak if it exceeds the previous maximum. Simultaneously, the counter for completed streaks (up_streaks_ended or down_streaks_ended) increments to track frequency. These persistent variables use var declaration so they retain values across bars and are never reset.

The histogram plots the active streak value each bar, colored green for positive streaks (consecutive up closes), red for negative streaks (consecutive down closes), and gray for zero. The statistics table updates each bar, so all values remain live and reflect the entire chart history accessible within the max_bars_back limit (500 bars by default).

Reading it on a chart

The column chart offers an immediate visual of momentum duration. Tall green columns indicate sustained buying pressure; tall red columns indicate sustained selling pressure. Columns shrinking toward zero signal momentum fatigue before reversals or consolidation.

The statistics table shows:

  • Active Streak: the current count, positive for up, negative for down. This is the most dynamic value and moves each bar.
  • Longest Up / Down: the peak streak lengths reached over the visible history. These reveal the market's maximum consecutive-close runs under current conditions.
  • Up Streaks Ended / Down Streaks Ended: frequency of completed directional runs. A large difference between the two may signal a directional bias in the timeframe.
  • Up Streak %: the proportion of completed streaks that were up versus down. Values above 50% indicate more frequent up runs; below 50% indicate more frequent down runs.

A trader might note that a fresh streak beginning after a long prior streak sometimes precedes fading (mean reversion), while extensions of already-long streaks may confirm conviction, depending on underlying fundamentals and market regime.

Limitations

This indicator counts consecutive closes purely on price; it does not account for volume, volatility, or gap magnitude. A single-tick up close counts equally with a multi-limit move up close. Wide-range gaps at open (common in overnight or post-news sessions) are invisible to the consecutive-close logic because the indicator only compares current close to prior close, not opens or highs/lows.

Streak statistics are cumulative within the chart window and max_bars_back setting. Extending the lookback period will increase streak counts and potentially reveal longer historical runs, while a shorter window may obscure prior streaks entirely. The statistics are not forward-looking; they describe history only.

Consecutive closes are not predictive of future performance. Academic research on momentum and mean reversion shows both effects are observable in markets depending on asset class, timeframe, and regime, but neither dominates universally [1]. Long streaks may reflect genuine trend strength or may be noise preceding sharp reversals. Traders must combine this indicator with support/resistance, volume analysis, and broader market context to avoid over-weighting consecutive-close patterns in isolation [2].

Flat closes (equal to prior close, common in currencies and index futures with discrete tick sizes) continue the current streak without incrementing, which can mask reversals in markets with low volatility or during consolidation phases where equality is frequent.


Key definitions

Consecutive close: a market close higher (or lower) than the prior market close, counted as a streak until the direction reverses or a flat close occurs.

Streak: an unbroken sequence of consecutive closes in one direction (all up or all down). The streak ends when a close in the opposite direction occurs.

Mean reversion: a hypothetical market behavior in which price movements away from a central level (mean) are followed by moves back toward that level; tested empirically across asset classes with mixed results depending on timeframe and regime.

Momentum: sustained directional price movement in one direction, often associated with trending behavior and positive autocorrelation of returns over short to medium horizons.

Hot hand fallacy: a cognitive bias in which an observer attributes a streak of successes to skill or causation rather than chance; relevant to streak interpretation because consecutive closes may appear significant to intuition but may not carry predictive power [1].

Persistence: the tendency of a price series to continue in one direction; mathematically distinct from mean reversion and observable at certain lags and timeframes in market data.


References

[1] Kahneman, D., & Tversky, A., "The hot hand in basketball: On the misperception of random sequences," Cognitive Psychology, vol. 17, no. 3, pp. 295-314 (1985). Https://doi.org/10.1016/0010-0285(85)90010-6

[2] Jegadeesh, N., & Titman, S., "Returns to buying winners and selling losers: Implications for stock market efficiency," The Journal of Finance, vol. 48, no. 1, pp. 65-91 (1993). Https://doi.org/10.1111/j.1540-6261.1993.tb04702.x

[3] Mclean, R. D., & Pontiff, J., "Does academic research destroy stock return predictability?" The Journal of Finance, vol. 71, no. 5, pp. 2541-2578 (2016). Https://doi.org/10.1111/jofi.12408

[4] CME Group, "Globex Market Data: Contract Specifications," CME Rulebook. Https://www.cmegroup.com/rulebook

[5] CFTC, "Understanding Futures," U.S. Commodity Futures Trading Commission. Https://www.cftc.gov/education


Educational research on historical data only. Not investment advice, not a signal, and never a performance promise. Past results do not predict future performance. Every reference is link-verified before publication and every paper is re-audited weekly against the library's editorial standard.

Last reviewed by the PropLedger research pipeline: 2026-11-15. Educational research on historical data, not financial advice.

Educational research on historical data only. Not investment advice, not a signal, and never a performance promise. Past results do not predict future performance. Every reference is link-verified before publication and every paper is re-audited weekly against the library's editorial standard. Found an error? Email support@prop-ledger.org and the paper is corrected or withdrawn.