Nicolas

ICT Toolkit: BOS, CHoCH, sweeps, fair value gaps and premium / discount

Studio Only
Category: Indicators By: Nicolas Created: December 2, 2026, 1:07 PM
December 2, 2026, 1:07 PM
Indicators
0 Comments
ProRealCode Script
ICT Toolkit: BOS, CHoCH, sweeps, fair value gaps and premium / discount

The concepts ICT traders draw by hand, computed by one code and kept up to date on every bar: market structure with its breaks and changes of character, liquidity sweeps, fair value gaps that stay on the chart until price fills them, the premium and discount halves of the dealing range, the liquidity still resting above and below it, and a dashboard that sums it all up.

This code is written in ProRealCode Script and runs with ProRealCode Studio on ProRealTime Web.

What it draws

  • BOS and CHoCH — a close beyond the last confirmed swing breaks the structure. Against the current trend it is a change of character (CHoCH, filled label); with it, a break of structure (BOS). A dashed line runs from the swing to the break.
  • Sweeps — a wick beyond the last swing that closes back inside: the liquidity resting there has been taken, but the structure has not been broken.
  • Fair value gaps — the three-candle imbalance, green for bullish and red for bearish. Each gap shrinks as price trades into it and disappears once it is completely filled; the 10 most recent open gaps are shown.
  • Premium and discount — the range between the last swing high and the last swing low, split at its equilibrium (EQ).
  • BSL and SSL — the buy-side and sell-side liquidity still resting at the last swing high and swing low, as long as price has not taken it.
  • The dashboard — structure, where the close sits in the range, the number of open gaps each way, and the two liquidity levels.

How it works

  • PivotHigh / PivotLow give confirmed swings that never repaint.
  • Four arrays ($gTop, $gBot, $gBar, $gDir) hold every gap, updated on each bar and trimmed with ARRAYSHIFT.
  • DRAWLABEL, DRAWSEGMENT, DRAWRECTANGLE draw the structure, the zones and the gaps; zones, gaps and dashboard are drawn on the last bar only (islastbarupdate).
  • DRAWTABLE with a TABLEBAR coloured by GRADIENTCOLOR builds the dashboard; a small FUNCTION formats the prices.
  • alert() fires on every change of character, with a JSON block for a webhook.

How to use it

Paste the code into a new Studio tab and press Ctrl + Enter. The swing length, the number of gaps shown and the smallest gap (in ATR) are fields of the Variables form; raise the swing length for a calmer structure on short timeframes. This is an illustration of the concepts, not a trading signal.

// ProRealCode Script example — an ICT toolkit
// Market structure (BOS and CHoCH), liquidity sweeps, fair value gaps that stay
// on the chart until price fills them, the premium and discount halves of the
// dealing range, and a dashboard. Built with functions, arrays, labels,
// gradients, a table and an alert.

input(swingLen, 5, "Swing length (bars on each side)", int)
input(maxGaps, 10, "Open fair value gaps shown", int)
input(minGapAtr, 0.2, "Smallest gap (in ATR)", float)

atr = AverageTrueRange[14](close)

// A level written once, used for every price shown in the dashboard
FUNCTION fmt(v)
ROUND(v * 100) / 100
ENDFUNCTION

// ── 1. Swings: confirmed pivots, never repainted ─────────────────────────────
ph = PivotHigh[swingLen, swingLen](high)
pl = PivotLow[swingLen, swingLen](low)
IF ISSET(ph) THEN
swingHigh = ph
swingHighBar = barindex - swingLen
highTaken = 0
ENDIF
IF ISSET(pl) THEN
swingLow = pl
swingLowBar = barindex - swingLen
lowTaken = 0
ENDIF

// ── 2. Liquidity sweeps and market structure ─────────────────────────────────
// A wick above the last swing high that closes back below it takes the
// buy-side liquidity; a close above it breaks the structure.
IF swingHigh > 0 AND highTaken = 0 AND high > swingHigh THEN
highTaken = 1
IF close < swingHigh THEN
DRAWLABEL(barindex, high + 0.4 * atr, "Sweep", arrowdown, tiny, "Buy-side liquidity taken above #swingHigh#") COLOURED(20, 22, 28) FILLCOLOR(240, 190, 70)
ELSE
DRAWSEGMENT(swingHighBar, swingHigh, barindex, swingHigh) COLOURED(60, 190, 120) STYLE(dashedline, 1)
IF trend = -1 THEN
DRAWLABEL(barindex, swingHigh + 0.3 * atr, "CHoCH", none, small, "Change of character: the bearish structure is broken") COLOURED(255, 255, 255) FILLCOLOR(40, 150, 95)
alert("ICT", "Bullish change of character at #close#", onceperbar, 1, {event: "choch", side: "long", price: close})
ELSE
DRAWLABEL(barindex, swingHigh + 0.3 * atr, "BOS", none, tiny, "Break of structure, trend continues up") COLOURED(60, 190, 120)
ENDIF
trend = 1
ENDIF
ENDIF

IF swingLow > 0 AND lowTaken = 0 AND low < swingLow THEN
lowTaken = 1
IF close > swingLow THEN
DRAWLABEL(barindex, low - 0.4 * atr, "Sweep", arrowup, tiny, "Sell-side liquidity taken below #swingLow#") COLOURED(20, 22, 28) FILLCOLOR(240, 190, 70)
ELSE
DRAWSEGMENT(swingLowBar, swingLow, barindex, swingLow) COLOURED(230, 90, 90) STYLE(dashedline, 1)
IF trend = 1 THEN
DRAWLABEL(barindex, swingLow - 0.3 * atr, "CHoCH", none, small, "Change of character: the bullish structure is broken") COLOURED(255, 255, 255) FILLCOLOR(175, 55, 65)
alert("ICT", "Bearish change of character at #close#", onceperbar, 1, {event: "choch", side: "short", price: close})
ELSE
DRAWLABEL(barindex, swingLow - 0.3 * atr, "BOS", none, tiny, "Break of structure, trend continues down") COLOURED(230, 90, 90)
ENDIF
trend = -1
ENDIF
ENDIF

// ── 3. Fair value gaps, kept in arrays until price fills them ────────────────
IF low > high[2] AND low - high[2] >= minGapAtr * atr THEN
ARRAYPUSH($gTop, low)
ARRAYPUSH($gBot, high[2])
ARRAYPUSH($gBar, barindex - 1)
ARRAYPUSH($gDir, 1)
ENDIF
IF high < low[2] AND low[2] - high >= minGapAtr * atr THEN
ARRAYPUSH($gTop, low[2])
ARRAYPUSH($gBot, high)
ARRAYPUSH($gBar, barindex - 1)
ARRAYPUSH($gDir, -1)
ENDIF

// Price eats into a gap: it shrinks, and disappears once filled
FOR i = 0 TO ARRAYSIZE($gDir) - 1 DO
IF $gDir[i] = 1 AND $gBar[i] < barindex - 1 THEN
IF low <= $gBot[i] THEN
$gDir[i] = 0
ELSIF low < $gTop[i] THEN
$gTop[i] = low
ENDIF
ELSIF $gDir[i] = -1 AND $gBar[i] < barindex - 1 THEN
IF high >= $gTop[i] THEN
$gDir[i] = 0
ELSIF high > $gBot[i] THEN
$gBot[i] = high
ENDIF
ENDIF
NEXT

// Keep the arrays short: the oldest entries leave from the front
WHILE ARRAYSIZE($gDir) > 200 DO
ARRAYSHIFT($gTop)
ARRAYSHIFT($gBot)
ARRAYSHIFT($gBar)
ARRAYSHIFT($gDir)
WEND

// ── 4. On the last bar: zones, liquidity and the dashboard ───────────────────
IF islastbarupdate AND swingHigh > 0 AND swingLow > 0 THEN
rangeStart = MIN(swingHighBar, swingLowBar)
rangeEnd = barindex + 12
eq = (swingHigh + swingLow) / 2

// Premium (upper half) and discount (lower half) of the dealing range
DRAWRECTANGLE(rangeStart, swingHigh, rangeEnd, eq) FILLCOLOR(230, 90, 90, 22)
DRAWRECTANGLE(rangeStart, eq, rangeEnd, swingLow) FILLCOLOR(60, 190, 120, 22)
DRAWSEGMENT(rangeStart, eq, rangeEnd, eq) COLOURED(150, 150, 165) STYLE(dottedline, 1)
DRAWLABEL(rangeEnd, eq, "EQ", none, tiny, right) COLOURED(150, 150, 165)
DRAWLABEL(rangeEnd, swingHigh, "Premium", none, tiny, right) COLOURED(230, 90, 90)
DRAWLABEL(rangeEnd, swingLow, "Discount", none, tiny, right) COLOURED(60, 190, 120)

// Liquidity still resting above the last swing high and below the last swing low
IF highTaken = 0 THEN
DRAWSEGMENT(swingHighBar, swingHigh, rangeEnd, swingHigh) COLOURED(240, 190, 70) STYLE(dottedline, 2)
DRAWLABEL(swingHighBar, swingHigh + 0.3 * atr, "BSL", none, tiny) COLOURED(240, 190, 70)
ENDIF
IF lowTaken = 0 THEN
DRAWSEGMENT(swingLowBar, swingLow, rangeEnd, swingLow) COLOURED(240, 190, 70) STYLE(dottedline, 2)
DRAWLABEL(swingLowBar, swingLow - 0.3 * atr, "SSL", none, tiny) COLOURED(240, 190, 70)
ENDIF

// The open fair value gaps, newest first
shown = 0
upGaps = 0
downGaps = 0
FOR i = ARRAYSIZE($gDir) - 1 DOWNTO 0 DO
IF $gDir[i] = 1 THEN
upGaps = upGaps + 1
ELSIF $gDir[i] = -1 THEN
downGaps = downGaps + 1
ENDIF
IF $gDir[i] <> 0 AND shown < maxGaps THEN
shown = shown + 1
IF $gDir[i] = 1 THEN
DRAWRECTANGLE($gBar[i], $gTop[i], rangeEnd, $gBot[i]) FILLCOLOR(60, 190, 120, 70) COLOURED(60, 190, 120)
ELSE
DRAWRECTANGLE($gBar[i], $gTop[i], rangeEnd, $gBot[i]) FILLCOLOR(230, 90, 90, 70) COLOURED(230, 90, 90)
ENDIF
ENDIF
NEXT

// Where the close sits in the range: 0% = swing low, 100% = swing high
pos = MAX(0, MIN(100, (close - swingLow) / (swingHigh - swingLow) * 100))
posTxt = ROUND(pos)
bsl = fmt(swingHigh)
ssl = fmt(swingLow)

board = DRAWTABLE(6, 2, topleft) FILLCOLOR(16, 20, 28, 235) BORDERCOLOR(48, 58, 76)
TABLEMERGE(board, 0, 0, 1, 2)
TABLECELL(board, 0, 0, "ICT dashboard", bold, center, 12) COLOURED(214, 222, 235)
TABLECELL(board, 1, 0, "Structure") COLOURED(170, 180, 195)
IF trend = 1 THEN
TABLECELL(board, 1, 1, "Bullish", bold) COLOURED(255, 255, 255)
TABLEBG(board, 1, 1, 40, 150, 95)
ELSIF trend = -1 THEN
TABLECELL(board, 1, 1, "Bearish", bold) COLOURED(255, 255, 255)
TABLEBG(board, 1, 1, 175, 55, 65)
ELSE
TABLECELL(board, 1, 1, "Undecided") COLOURED(170, 180, 195)
ENDIF
TABLECELL(board, 2, 0, "Range position") COLOURED(170, 180, 195)
TABLEBAR(board, 2, 1, pos, 0, 100, "#posTxt#%") GRADIENTCOLOR(pos, 0, 100, "#3fbf7f", "#8fa4c0", "#e05563")
TABLECELL(board, 3, 0, "Open gaps up / down") COLOURED(170, 180, 195)
TABLECELL(board, 3, 1, "#upGaps# / #downGaps#") COLOURED(214, 222, 235)
TABLECELL(board, 4, 0, "Buy-side liquidity") COLOURED(170, 180, 195)
TABLECELL(board, 4, 1, "#bsl#") COLOURED(240, 190, 70)
TABLECELL(board, 5, 0, "Sell-side liquidity") COLOURED(170, 180, 195)
TABLECELL(board, 5, 1, "#ssl#") COLOURED(240, 190, 70)
ENDIF

RETURN
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.
Nicolas
Nicolas Legend
I created ProRealCode because I believe in the power of shared knowledge. I spend my time coding new tools and helping members solve complex problems. If you are stuck on a code or need a fresh perspective on a strategy, I am always willing to help. Welcome to the community!
Author’s Profile

Comments

ProRealCode ProRealCode
Loading...