Retest Activity Range – Code2trade Strategy

1. Retest Activity Range – Code2trade Strategy

An indicator that anchors a trading range to each local spike in volume, then profiles where volume concentrated inside that range and signals breakouts/retests of its edges

1.1 Indicator Concept

Most range/zone indicators anchor themselves to price structure (a swing high, a swing low, a pattern). This one anchors itself to trading activity itself: it looks for bars where volume - not price - spikes above the volume of the surrounding bars. The idea is that a sudden burst of volume marks a moment when a disproportionate amount of trading interest concentrated at that price level, making the high/low of that single bar a meaningful boundary worth tracking going forward.

  • One volume spike = one new range: every time a new "volume pivot" bar is confirmed, the high and low of that one bar become the fixed ceiling and floor of a brand-new range box that then persists (and keeps extending to the right) until the next volume spike replaces it.
  • Built-in volume profile: while a range is active, every bar's volume is distributed across price rows spanning the range (a mini volume profile), so you can see where inside the range trading activity concentrated - and a dashed Point of Control (POC) line marks the single price row with the most volume.
  • Breakout/Retest signals: two selectable signal styles watch for price crossing the range's high/low (Breakout) or opening beyond an edge and closing back inside it (Retest), marking each with a small triangle.
  • Self-correcting on confirmation: because a volume pivot can only be confirmed length bars after it happens, the indicator retroactively replays the most recent length bars against the newly-confirmed range the moment it's confirmed - see 1.4 for what this means for signals near the "live edge" of the chart.

1.2 Indicator Features

  • Range Box:
    • A translucent box spanning from the volume-pivot bar's high to its low, stretching from that bar across time to the present. Green tint (default) if the pivot bar itself closed bullish, red tint (default) if it closed bearish. Both colors are user-configurable.
    • Once the next volume pivot is confirmed, the previous box's right edge is trimmed to stop exactly where the new range begins, so ranges appear as consecutive, non-overlapping blocks.
  • Average Line: a solid horizontal line at the exact midpoint of the range (average of the pivot bar's high and low) - acts as the range's built-in midline for signal-state resets (see 1.4).
  • Point of Control (POC) Line: a dashed horizontal line that continuously moves to sit at whichever price row inside the range has accumulated the most volume so far - the single most "fought over" price level within the range.
  • Volume Profile (optional): a row-by-row horizontal histogram drawn inside the range, hugging its right edge, showing the relative volume traded at each price level - longer bars mean more volume traded at that price.
  • Breakout/Retest Signal Triangles: a small ▲ below the bar or ▼ above the bar whenever price crosses the range's edges according to the selected Signal Mode.
💡 Note: this indicator does not define any alertcondition() - the triangles are chart markers only and cannot be wired to a TradingView alert directly.

1.3 How to Use the Indicator

  • Treat each range's high/low as a reaction zone: because the range is born from an unusually large burst of volume, its top and bottom are natural candidates for future support/resistance - watch how price behaves when it later revisits them.
  • Use the POC line as a magnet/fair-value level: the POC marks where the heaviest trading happened inside the range; price often gravitates back toward this level after moving away from it.
  • Read the Volume Profile shape: a profile bulging near the top of the range means most trading happened up high (weak floor, strong ceiling test already happened); a profile bulging near the bottom suggests the opposite; a thin middle with two fat ends can hint at a range that saw two separate pushes.
  • Choose the Signal Mode that matches your style: "Breakout" flags a close pushing cleanly beyond the range's high/low (momentum continuation entries); "Retest" flags a bar that opened beyond an edge but closed back inside it (a failed push back into the range, useful for fade/reversal-style entries).
  • Don't fully trust markers in the last length bars: since confirmation of a new volume pivot is delayed by length bars, signals and range boundaries near the most recent bars can still be revised (deleted and redrawn) once the next volume spike confirms - treat the very edge of the chart as provisional until it "settles".

1.4 How the Indicator Works

Inputs & Roles

  • length ("Pivot Length", Integer, default: 10, min 1): number of bars required on both sides of a volume bar for it to be confirmed as a "volume pivot" (via ta.pivothigh(volume, length, length)) - the bar whose trading volume exceeds all length bars to its left AND all length bars to its right. Example: length=10 means a bar's volume must be the highest among a 21-bar window (10 before + itself + 10 after) before it's confirmed - and because the 10 "after" bars must have closed first, confirmation always arrives 10 bars late. Increase → only truly exceptional volume spikes qualify (fewer, longer-lived ranges, but more bars of delayed confirmation/replay each time). Decrease → more frequent, shorter-lived ranges, with less delay before confirmation.
  • signalMode ("Signal Mode", Options: Breakout / Retest, default: Retest): selects which price-action pattern triggers the ▲/▼ triangles. Breakout: the bar's close crosses from inside the range to outside it (a clean push through). Retest: the bar opens beyond an edge but its close ends back inside the range (price pushed out, then pulled back in during the same bar). Example with a range top at $100: a bar with open=$98, close=$102 fires a Breakout up-signal; a bar with open=$102, close=$99 fires a Retest up-signal instead (opened above $100, closed back below it).
  • showVp ("Show Volume Profile", Boolean, default: true): shows/hides the row-by-row volume histogram inside the active/most recent range. Turning it off does not stop volume from being tracked internally (the POC line keeps working), it only hides the histogram boxes.
  • vpRows ("Profile Rows", Integer, default: 10, range 1-50): how many horizontal price bands the range's height is divided into for the volume profile and the POC calculation. Example: a range spanning $100-$110 with vpRows=10 creates 10 rows of $1 each; the POC line can then only land on one of those 10 row-midpoints (e.g. $100.5, $101.5, ...). Increase → finer price resolution, more precise POC, but more boxes drawn (heavier on the box-count limit). Decrease → coarser resolution, fewer boxes.
  • vpWidthPct ("Max Width %", Integer, default: 20, range 1-100): caps how far (as a percentage of the range's elapsed duration in bars) the longest volume-profile bar is allowed to stretch leftward from the range's right edge. Example: a range that has lasted 50 bars so far with vpWidthPct=20 → the single highest-volume row's bar can be at most 10 bars wide; every other row is scaled proportionally shorter based on its share of the peak volume. Increase → wider, more prominent profile bars. Decrease → thinner, more subtle bars that take up less chart space.
  • bullColor / bearColor: fill color for the range box depending on whether the originating volume-pivot bar closed bullish or bearish. Purely cosmetic.
  • bullLineColor / bearLineColor: color of the average line, the POC line, and (implicitly, since it reuses currentBoxColor) the volume profile bars, matched to the range's bull/bear tint. Purely cosmetic.
  • signalUpColor / signalDownColor: color of the ▲ and ▼ signal triangles. Purely cosmetic.

Main Logic Blocks

🎯 Flow 1: What You See — The Active Range, POC & Volume Profile

  • At any moment, one range box is "live": its left edge is fixed at the last confirmed volume-pivot bar, and its right edge silently extends by one bar every single bar that passes (whether or not a new pivot is forming), so the box always reaches up to the current bar.
  • Inside it, the solid average line sits frozen at the exact midpoint of the pivot bar's high/low, while the dashed POC line continuously re-positions itself to track whichever price row is currently holding the most accumulated volume - it can move up or down as more bars add volume to different rows.
  • If enabled, the volume-profile histogram redraws every bar too: each row's bar length is rescaled relative to the row with the most volume, and the whole histogram stays anchored to the range's current right edge.

🌱 Flow 2: How a New Range Is Born — Volume Pivot Detection

  • Every bar, ta.pivothigh(volume, length, length) checks whether the bar length bars back had the single highest trading volume among the length bars before it and the length bars after it (the current bar being the last of those "after" bars). Only once that's true does a new range get triggered - this is a volume comparison, completely independent of price direction or price levels.
  • When a new volume pivot is confirmed, pivotHigh = high[length] and pivotLow = low[length] (the exact high/low of that one spike bar, not an accumulated range) become the new range's fixed ceiling and floor, and isBull = close[length] ≥ open[length] decides the box's bull/bear tint.

🔧 Flow 3: Closing Out the Previous Range

  • Before drawing anything new, the indicator finalizes what came before: if a volume profile was being tracked, it gets one last updateVpBoxes() call so its histogram freezes exactly at the new pivot's position instead of stretching further; the previous range's box and its average/POC lines all get their right edge trimmed to that same position, so the old and new ranges meet cleanly with no overlap.
  • Any signal triangles that were placed provisionally (in real-time, before this pivot was confirmed) at a bar position that now falls inside the newly-confirmed range's territory are deleted - they will be recalculated fresh in Flow 4 below, now measured against the correct, final range boundaries instead of the old (now superseded) ones.

🔄 Flow 4: Retroactive Replay of the Last length Bars

  • Once the new range's fixed high/low/average are known, the indicator loops back over the length bars leading up to (and including) the current bar and re-evaluates each one as if the range had existed the whole time:
  • Midline reset: whenever a replayed bar's close crosses the average line (from either side), the internal signal state resets to neutral - this is what allows a fresh ▲ or ▼ to fire again later even in the same direction as a previous one, as long as price touched the midline in between.
  • Signal check: for each replayed bar, the Breakout or Retest condition (per signalMode, see Inputs above) is tested against the range's fixed pivotHigh/pivotLow. If it fires and the state isn't already showing that same direction, a triangle label is placed at that bar's true historical position and tracked in a list for possible future cleanup.
  • Volume profile accumulation: each replayed bar's volume is distributed across the range's price rows (see Flow 6) so the profile and POC reflect the true volume distribution from the very start of the range, not just from the moment it was confirmed.
  • After the replay finishes, the POC line and (if enabled) the volume-profile boxes are updated one more time to reflect everything accumulated so far, right up to the current bar.

⏱️ Flow 5: Real-Time Continuation (No New Pivot This Bar)

  • On every bar where no new volume pivot is confirmed, the active range's box and its average/POC lines simply extend one bar further to the right - keeping the visuals in sync with the live chart.
  • The exact same midline-reset, signal-check, and volume-accumulation logic from Flow 4 is applied to just the current bar (no replay needed, since there's nothing new to reconcile) - so signals and the volume profile update live, bar by bar, in between confirmed pivots.

📊 Flow 6: The Volume Profile Engine

  • Distributing one bar's volume (addVolume): the range's height is divided into vpRows equal price bands. A bar's volume is spread across every band its high-low range touches, proportional to how much of the bar's range falls in that band. Example: range rows are $1 tall, a bar has low=$102/high=$104 (a $2 range) and volume=500 - the band $102-$103 gets 50% of the bar's range → 250 volume, and the band $103-$104 gets the other 250. A bar with identical high and low (a single traded price) instead dumps its full volume into whichever single band contains that price.
  • Finding the POC (updatePoc): after accumulation, the price band holding the largest total volume is located, and the POC line is moved to sit at the exact midpoint price of that band.
  • Drawing the histogram (updateVpBoxes): for each band, its accumulated volume is compared to the single largest band's volume to get a 0-100% share; that share is multiplied by the maximum allowed bar length (vpWidthPct% of the range's elapsed duration) to get that band's box width, which is then drawn growing leftward from the range's current right edge.

Outputs & Usage Roles

  • Range box: the primary output - a volume-anchored zone whose top/bottom can act as support/resistance.
  • Average line: the range's midline, mainly an internal reference for when signals are allowed to re-fire, but also visually useful as the range's "center".
  • POC line: the single price level with the heaviest trading activity in the range - a candidate magnet/fair-value level.
  • Volume profile: a visual breakdown of where within the range trading activity concentrated.
  • ▲/▼ triangles: visual breakout or retest markers at the range's edges (chart markers only - no built-in alerts, see 1.2).
💡 Note on repainting near the live edge: because a volume pivot can only confirm length bars after the fact, everything drawn in that trailing window - the range boundaries, the volume profile, and any signal triangles - is provisional and can be deleted/redrawn once the next pivot confirms and the true range boundaries become known. This is a deliberate, self-consistent design (not a bug), but it means the most recent length bars of output should be treated as "settling" rather than final.
Zoom/Pan Layered Image
Background Overlay
− +

The indicator above just became a TRADING BOT — 1 AI click

📊Original indicator
→
🤖AI 1-click convert
→
⚙️Bot trading 24/7