Iván González

Smart Money Bull/Bear Trap Detector: Ranked Liquidity Sweeps

Studio Only
Category: Indicators By: Iván González Created: December 4, 2026, 4:28 PM
December 4, 2026, 4:28 PM
Indicators
0 Comments
ProRealCode Script
Smart Money Bull/Bear Trap Detector: Ranked Liquidity Sweeps

Introduction

 

Fresh swing highs and swing lows are where stop orders pile up. When price spikes through one of those levels and then closes back on the other side, the breakout traders are trapped and the stops above or below the level have been taken. The Smart Money Bull/Bear Trap Detector by BigBeluga finds those sweeps automatically, marks the level that was swept and grades every signal from A to C according to how fresh the level was and how much volume came with the sweep.

Theory Behind the Indicator

 

Pivot levels. A pivot high is a bar whose high is above the highs of the pLegs bars on each side (10 by default); a pivot low is the mirror case. Every pivot becomes a level with a short gradient zone attached to it: below the high for resistance (red), above the low for support (turquoise). The zone is 15% of the range of the pivot candle tall and is split into segments that fade out as they move away from the pivot.

The trap. While a level is alive, the indicator watches for a bar that pierces it with the wick and closes back inside:

  • At a pivot high: the high goes above the level but the close stays below it. Buyers who chased the breakout are trapped (arrow ▼).
  • At a pivot low: the low goes below the level but the close stays above it. Sellers who chased the breakdown are trapped (arrow ▲).

Each level can fire only once. A level is dropped after it fires or when it gets too old: zLen bars (35 by default), or twice that if the expiration option is switched off.

The score. Every trap receives up to four points:

  • Freshness: 2 points if the level is no older than one third of zLen bars, 1 point if it is no older than two thirds.
  • Volume: 2 points if the volume of the sweep bar is above vThresh times its 20-bar average (1.2 by default), 1 point if it is simply above the average.

Three or more points give an A signal, two points a B, and anything less a C.

Key Features at a Glance

 

  • Automatic detection of liquidity sweeps on recent pivot highs and lows.
  • Gradient zones that show where each level was born and how long it stays relevant.
  • A, B and C ranking based on level freshness and relative volume, with one colour per rank.
  • One signal per level: once a level has trapped the market it leaves the queue.
  • Optional expiration of the levels after the zone length.
  • Dashboard with the last five signals, their rank and how many bars ago they happened, in any corner of the chart or in the center.

How to Read the Indicator

 

  • ▼ with a letter above a candle: bear signal. The high swept a recent pivot high and the bar closed back below it.
  • ▲ with a letter below a candle: bull signal. The low swept a recent pivot low and the bar closed back above it.
  • The letter: A (gold) is a sweep of a very fresh level with strong volume; B (amber) is a moderate setup; C (rust) is the weakest combination.
  • Gradient zones: the darker part sits right at the pivot and the colour fades towards the right. A zone without a signal is a level that has not been swept yet, or has expired.
  • Dashboard: SIGNAL shows the direction, RANK the grade and AGE the number of bars since the signal. The newest signal is on the first row.

Practical Applications

 

  • Reversal entries. An A signal at a pivot high in a range or at the end of an extended move is a candidate for a short, with the sweep high as the natural invalidation; the mirror case applies at pivot lows.
  • Filter for breakout trades. If the bar that breaks a pivot closes back inside and prints a signal, the breakout failed. That is useful information before adding to a position.
  • Selecting the best setups. Many traders only act on A and B signals and use C signals as context.
  • Confluence. Sweeps that line up with order blocks, fair value gaps or higher timeframe levels tend to be the cleanest.

Indicator Configuration

 

  • Pivot and trap detection:
  • Pivot strength (default: 10): bars required on each side to confirm a pivot.
  • Gradient segments per zone (default: 10): from 2 to 15.
  • Base zone length (default: 35 bars): also used for the expiration and the freshness score.
  • Stop detection after zone expiration (default: on): on, a level stops looking for sweeps once it is older than the zone length; off, it keeps looking for twice that.
  • High volume multiplier (default: 1.2): multiplier of the 20-bar volume average that defines high volume.
  • Chart signals: label size (default: normal).
  • Colours: resistance and support zones, and the A, B and C signals.
  • Dashboard: show it (default: on), its position (top right by default; also top left, bottom right, bottom left and center) and its background, border, header, age, bull and bear text colours.

The Code

 

This is the ProRealCode Studio version: paste it into a new ProRealCode Studio tab on ProRealTime Web.

//---------------------------------------------------------------
// PRC_SMC Bull Bear Traps
// version = 0
// 04.12.2026
// Iván González @ www.prorealcode.com
// Author: BigBeluga
// Sharing ProRealTime knowledge
//---------------------------------------------------------------
// Liquidity sweeps ("traps") over recent pivots, scored from 0 to 4.
// Each pivot draws a fading zone. A candle whose wick goes through a live
// pivot and closes back on the other side is a trap: the fresher the level
// and the higher the volume, the better the rank (A, B or C). A dashboard
// lists the last five signals.
//---------------------------------------------------------------
DEFPARAM DRAWONLASTBARONLY = true

// ------------------------------- SETTINGS
input(pLegs, 10, "Pivot strength (left/right)", int, minval = 2, group = "Pivot and trap detection", tooltip = "Bars on each side that confirm a pivot high or low")
input(zSegs, 10, "Gradient segments per zone", int, minval = 2, maxval = 15, group = "Pivot and trap detection")
input(zLen, 35, "Base zone length (bars)", int, minval = 10, group = "Pivot and trap detection")
input(useZlenExpire, 1, "Stop detection after zone expiration", bool, group = "Pivot and trap detection", tooltip = "Off: a level keeps looking for sweeps up to twice the zone length")
input(vThresh, 1.2, "High volume multiplier", float, minval = 0.5, step = 0.1, group = "Pivot and trap detection", tooltip = "Multiplier over the 20-bar volume average")

input(lblSz, "normal", "Signal label size", string, options = ["tiny", "small", "normal", "large", "huge"], group = "Chart signals")
input(cRes, "#FF2E63", "Resistance zones (pivot highs)", color, group = "Colours")
input(cSup, "#00F5D4", "Support zones (pivot lows)", color, group = "Colours")
input(cRankA, "#FFE600", "Rank A", color, group = "Colours", inline = "rk")
input(cRankB, "#FF9F1C", "B", color, group = "Colours", inline = "rk")
input(cRankC, "#E76F51", "C", color, group = "Colours", inline = "rk")

input(sDash, 1, "Show dashboard", bool, group = "Dashboard")
input(dPos, "Top Right", "Position", string, options = ["Top Right", "Top Left", "Bottom Right", "Bottom Left", "Center"], group = "Dashboard")
input(dBgCol, "#0B0E14", "Background", color, group = "Dashboard", inline = "d1")
input(dBrdCol, "#2A3447", "border", color, group = "Dashboard", inline = "d1")
input(dHdrTxt, "#94A3B8", "Header text", color, group = "Dashboard", inline = "d2")
input(dAgeTxt, "#CBD5E1", "age text", color, group = "Dashboard", inline = "d2")
input(dBullTx, "#00F5D4", "Bull text", color, group = "Dashboard", inline = "d3")
input(dBearTx, "#FF2E63", "bear text", color, group = "Dashboard", inline = "d3")

// ------------------------------- HELPERS
// A colour from input() arrives as the number 0xRRGGBB. Used from a variable
// together with an alpha it stops the script at run time, so every colour
// that needs transparency goes as R, G, B.
FUNCTION rgb(c)
RETURN floor(c / 65536), floor(c / 256) MOD 256, c MOD 256
ENDFUNCTION

// One signal mark (arrow or rank letter): the label size is a keyword,
// so there is one branch per size
FUNCTION mark(x, y, t, c)
IF lblSz = "tiny" THEN
DRAWLABEL(x, y, t, none, tiny, center) COLOURED(c) FILLCOLOR(0, 0, 0, 0) BORDERCOLOR(0, 0, 0, 0)
ELSIF lblSz = "small" THEN
DRAWLABEL(x, y, t, none, small, center) COLOURED(c) FILLCOLOR(0, 0, 0, 0) BORDERCOLOR(0, 0, 0, 0)
ELSIF lblSz = "large" THEN
DRAWLABEL(x, y, t, none, large, center) COLOURED(c) FILLCOLOR(0, 0, 0, 0) BORDERCOLOR(0, 0, 0, 0)
ELSIF lblSz = "huge" THEN
DRAWLABEL(x, y, t, none, huge, center) COLOURED(c) FILLCOLOR(0, 0, 0, 0) BORDERCOLOR(0, 0, 0, 0)
ELSE
DRAWLABEL(x, y, t, none, normal, center) COLOURED(c) FILLCOLOR(0, 0, 0, 0) BORDERCOLOR(0, 0, 0, 0)
ENDIF
1
ENDFUNCTION

// ------------------------------- STATE
ONCE nPv = 0          // pivot levels stored (append only)
ONCE pvStart = 0      // first level that can still be active
ONCE nSg = 0          // signals stored (append only)

legs = max(2, round(pLegs))
segs = max(2, min(15, round(zSegs)))
vMa = average[20](volume)
myAtr = averagetruerange[14](close)

// ------------------------------- PIVOTS
// strict against the later bars, >= against the earlier ones
pivHi = 0
pivLo = 0
IF barindex >= 2 * legs THEN
   hhR = highest[legs](high)
   IF high[legs] > hhR AND high[legs] >= hhR[legs + 1] THEN
      pivHi = 1
   ENDIF
   llR = lowest[legs](low)
   IF low[legs] < llR AND low[legs] <= llR[legs + 1] THEN
      pivLo = 1
   ENDIF
ENDIF

// each pivot becomes a level with its zone (15% of the pivot candle range)
IF pivHi THEN
   bRng = high[legs] - low[legs]
   $pvP[nPv] = high[legs]
   $pvX[nPv] = barindex - legs
   $pvH[nPv] = 1
   $pvTop[nPv] = high[legs]
   $pvBot[nPv] = high[legs] - bRng * 0.15
   $pvTrg[nPv] = -1
   nPv = nPv + 1
ENDIF
IF pivLo THEN
   bRng = high[legs] - low[legs]
   $pvP[nPv] = low[legs]
   $pvX[nPv] = barindex - legs
   $pvH[nPv] = 0
   $pvTop[nPv] = low[legs] + bRng * 0.15
   $pvBot[nPv] = low[legs]
   $pvTrg[nPv] = -1
   nPv = nPv + 1
ENDIF

// ------------------------------- TRAP DETECTION
// A level leaves the queue once it has fired or once it is older than its
// maximum age. The trigger bar is stored and re-evaluated on every tick of
// that same bar, so a sweep that is undone before the close leaves no signal.
IF useZlenExpire THEN
   maxAge = zLen
ELSE
   maxAge = zLen * 2
ENDIF
WHILE pvStart < nPv AND barindex - $pvX[pvStart] > maxAge DO
   pvStart = pvStart + 1
WEND
IF nPv > pvStart THEN
   FOR i = nPv - 1 DOWNTO pvStart DO
      age = barindex - $pvX[i]
      alive = age <= maxAge
      IF $pvTrg[i] >= 0 AND $pvTrg[i] < barindex THEN
         alive = 0
      ENDIF
      IF alive THEN
         isTrap = 0
         IF useZlenExpire = 0 OR age <= zLen THEN
            IF $pvH[i] = 1 THEN
               // wick above the pivot high, close back below it
               isTrap = high > $pvP[i] AND close < $pvP[i]
            ELSE
               // wick below the pivot low, close back above it
               isTrap = low < $pvP[i] AND close > $pvP[i]
            ENDIF
         ENDIF
         IF isTrap THEN
            $pvTrg[i] = barindex
            // score: freshness of the level + volume
            ageTerm = (age <= zLen / 3) + (age <= (2 * zLen) / 3)
            // the multiplier may be below 1, so the two tests are not nested
            IF volume > vMa * vThresh THEN
               volTerm = 2
            ELSE
               volTerm = volume > vMa
            ENDIF
            pts = ageTerm + volTerm
            IF pts >= 3 THEN
               $sgRk[nSg] = 1
            ELSIF pts = 2 THEN
               $sgRk[nSg] = 2
            ELSE
               $sgRk[nSg] = 3
            ENDIF
            $sgX[nSg] = barindex
            $sgH[nSg] = $pvH[i]
            IF $pvH[i] = 1 THEN
               $sgY[nSg] = high
            ELSE
               $sgY[nSg] = low
            ENDIF
            $sgAtr[nSg] = myAtr
            nSg = nSg + 1
         ELSE
            $pvTrg[i] = -1
         ENDIF
      ENDIF
   NEXT
ENDIF

// ------------------------------- DRAWING
IF islastbarupdate THEN
   (rsR, rsG, rsB) = rgb(cRes)
   (spR, spG, spB) = rgb(cSup)

   // gradient zones: the 500 most recent boxes, as many as the original keeps
   sLen = floor(zLen / segs)
   boxLeft = 500
   k = nPv - 1
   WHILE k >= 0 AND boxLeft > 0 DO
      sg = segs - 1
      WHILE sg >= 0 AND boxLeft > 0 DO
         b1 = $pvX[k] + sg * sLen
         b2 = b1 + sLen
         alphaZ = round(255 * (70 - floor(sg * (70 / segs))) / 100)
         IF $pvH[k] = 1 THEN
            DRAWRECTANGLE(b1, $pvTop[k], b2, $pvBot[k]) COLOURED(rsR, rsG, rsB, 0) FILLCOLOR(rsR, rsG, rsB, alphaZ)
         ELSE
            DRAWRECTANGLE(b1, $pvTop[k], b2, $pvBot[k]) COLOURED(spR, spG, spB, 0) FILLCOLOR(spR, spG, spB, alphaZ)
         ENDIF
         boxLeft = boxLeft - 1
         sg = sg - 1
      WEND
      k = k - 1
   WEND

   // signal labels: arrow next to the wick, rank letter beyond it
   IF nSg > 0 THEN
      FOR j = nSg - 1 DOWNTO max(0, nSg - 500) DO
         IF $sgRk[j] = 1 THEN
            lc = cRankA
            lt = "A"
         ELSIF $sgRk[j] = 2 THEN
            lc = cRankB
            lt = "B"
         ELSE
            lc = cRankC
            lt = "C"
         ENDIF
         IF $sgH[j] = 1 THEN
            mark($sgX[j], $sgY[j] + 0.5 * $sgAtr[j], "▼", lc)
            mark($sgX[j], $sgY[j] + 1.4 * $sgAtr[j], lt, lc)
         ELSE
            mark($sgX[j], $sgY[j] - 0.5 * $sgAtr[j], "▲", lc)
            mark($sgX[j], $sgY[j] - 1.4 * $sgAtr[j], lt, lc)
         ENDIF
      NEXT
   ENDIF

   // dashboard: the last five signals, newest first
   IF sDash THEN
      (bgR, bgG, bgB) = rgb(dBgCol)
      (brR, brG, brB) = rgb(dBrdCol)
      nRows = min(5, nSg) + 1
      // the table corner is a keyword, not a variable
      IF dPos = "Top Left" THEN
         tb = DRAWTABLE(nRows, 3, topleft) FILLCOLOR(bgR, bgG, bgB) BORDERCOLOR(brR, brG, brB)
      ELSIF dPos = "Bottom Right" THEN
         tb = DRAWTABLE(nRows, 3, bottomright) FILLCOLOR(bgR, bgG, bgB) BORDERCOLOR(brR, brG, brB)
      ELSIF dPos = "Bottom Left" THEN
         tb = DRAWTABLE(nRows, 3, bottomleft) FILLCOLOR(bgR, bgG, bgB) BORDERCOLOR(brR, brG, brB)
      ELSIF dPos = "Center" THEN
         tb = DRAWTABLE(nRows, 3, center) FILLCOLOR(bgR, bgG, bgB) BORDERCOLOR(brR, brG, brB)
      ELSE
         tb = DRAWTABLE(nRows, 3, topright) FILLCOLOR(bgR, bgG, bgB) BORDERCOLOR(brR, brG, brB)
      ENDIF
      TABLECELL(tb, 0, 0, "SIGNAL") COLOURED(dHdrTxt)
      TABLECELL(tb, 0, 1, "RANK") COLOURED(dHdrTxt)
      TABLECELL(tb, 0, 2, "AGE") COLOURED(dHdrTxt)
      IF nRows > 1 THEN
         FOR rw = 1 TO nRows - 1 DO
            s = nSg - rw
            ageS = barindex - $sgX[s]
            IF $sgRk[s] = 1 THEN
               rc = cRankA
               rt = "[A]"
            ELSIF $sgRk[s] = 2 THEN
               rc = cRankB
               rt = "[B]"
            ELSE
               rc = cRankC
               rt = "[C]"
            ENDIF
            IF $sgH[s] = 1 THEN
               TABLECELL(tb, rw, 0, "▼ BEAR") COLOURED(dBearTx)
               FOR cl = 0 TO 2 DO
                  TABLEBG(tb, rw, cl, rsR, rsG, rsB, 20)
               NEXT
            ELSE
               TABLECELL(tb, rw, 0, "▲ BULL") COLOURED(dBullTx)
               FOR cl = 0 TO 2 DO
                  TABLEBG(tb, rw, cl, spR, spG, spB, 20)
               NEXT
            ENDIF
            TABLECELL(tb, rw, 1, rt) COLOURED(rc)
            TABLECELL(tb, rw, 2, "#ageS#b ago") COLOURED(dAgeTxt)
         NEXT
      ENDIF
   ENDIF
ENDIF

RETURN

Original author: BigBeluga, published open source under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International license (CC BY-NC-SA 4.0).

No ITF file for this code
A Studio Only code is not imported into ProRealTime™. Copy it and paste it into the ProRealCode Studio editor.
Iván González
Iván González Legend
As an architect of digital worlds, my own description remains a mystery. Think of me as an undeclared variable, existing somewhere in the code.
Author’s Profile

Comments

ProRealCode ProRealCode
Loading...