Indicator · Pine Script v5 · On the chart

Zen Gaps v5.0

by Zen-Tim

This indicator draws colored boxes on the price chart to highlight gaps between bars.

View on GitHub

GitHub stars29on the repository
Pine versionv5runs as is
Lines of code150
Settings19inputs
LicenceMIT
Last update2 weeks ago14 Oct 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

150 lines of Pine Script v5 from indicators/Zen-Gaps/zen-gaps-v5.0.txt, published under MIT. Keep the author's credit and licence lines when you reuse it.

zen-gaps-v5.0.txt
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Zen_Tim_Trades

//@version=5
indicator("Zen Gaps v5.0 · 20260923", shorttitle="Zen Gaps v5.0", overlay = true, max_labels_count=100, max_lines_count = 100)



bool plotTickGaps = input.string("On", "Show Tick Gaps ?", options = ["On", "Off"]) == "On"
bool plotUrgentBars = input.string("On", "Show Urgent Bars ?", options = ["On", "Off"]) == "On"
bool plotClarityBars = input.string("On", "Show Clarity?", options = ["On", "Off"]) == "On"

i_bullIBSfactor = input.int(69, "Bull IBS Threshold", minval = 51, maxval = 99)
I_bearIBSfactor = input.int(31, "Bear INS Threshold", minval = 1, maxval = 49)
UrgencyBullThreshold  = input(title = "Urgency Bull %", defval = 15)
UrgencyBearThreshold  = input(title = "Urgency Bear %", defval = 15)
BodyRangeThreshold  = input(title = "Body Range Limit", defval = 51)

//Set Input Colours
bullGapBGColor = input(color.rgb(76, 175, 79, 95), 'Bullish Gap Background')
bullGapBorderColor = input(color.rgb(76, 175, 79, 100), 'Bullish Gap Border')
strongBullGapBGColor = input(color.rgb(55, 188, 255, 80), 'Strongly Bullish Gap Background')
strongBullGapBorderColor = input(color.rgb(66, 116, 187, 100), 'Strongly Bullish Gap Border')
bearGapBGColor = input(color.rgb(255, 82, 82, 92), 'Bearish Gap Background')
bearGapBorderColor = input(color.rgb(255, 82, 82, 100), 'Bearish Gap Border')
strongBearGapBGColor = input(color.rgb(55, 188, 255, 80), 'Strongly Bearish Gap Background')
strongBearGapBorderColor = input(color.rgb(66, 116, 187, 100), 'Strongly Bearish Gap Border')

//bull and bear bar
bullBar = close > open
bearBar = open > close
priorBullBar = close[2] > open[2]
priorBearBar = open[2] > close[2]

//Determine Gap direction
bullGap = low > high[2] 
bearGap = high < low[2]

//Determine Gap Strength
currentbarStatus = (close >= open ? 1 : 0)
priorbarStatus = (close[2] >= open[2] ? 1 : 0)
isStrongGap = currentbarStatus == priorbarStatus ? 1 : 0




if bullGap 
    if isStrongGap > 0
        if bullBar
            if priorBullBar
                strongbullGapDraw = box.new(left = bar_index[2], top = low, right = bar_index, bottom = high[2], border_color = strongBullGapBorderColor, border_width = 2, border_style = line.style_solid, bgcolor = strongBullGapBGColor)
    else 
        bullGapDraw = box.new(left = bar_index[2], top = low, right = bar_index, bottom = high[2], border_color = bullGapBorderColor, border_width = 2, border_style = line.style_solid, bgcolor = bullGapBGColor)

if bearGap
    if  isStrongGap > 0
        if bearBar
            if priorBearBar
                strongbearGapDraw = box.new(left = bar_index[2], top = low[2], right = bar_index, bottom = high, border_color = strongBearGapBorderColor, border_width = 2, border_style = line.style_solid, bgcolor = strongBearGapBGColor)
    else
        bearGapdraw = box.new(left = bar_index[2], top = low[2], right = bar_index, bottom = high, border_color = bearGapBorderColor, border_width = 2, border_style = line.style_solid, bgcolor = bearGapBGColor)

//Tick Gaps
bulltickgap = open > close[1]
beartickgap = open < close[1]

showbulltickgap = bulltickgap and plotTickGaps == true
showbeartickgap = beartickgap and plotTickGaps == true

//

var line lineBull = na
var line lineBear = na
var int lineBullBar = na
var int lineBearBar = na

if showbulltickgap
    //line.delete(lineBull)
    lineBull := line.new(x1=bar_index - 1, y1=open, x2=bar_index + 2, y2=open, color=color.green)
    lineBullBar := bar_index

if showbeartickgap
   // line.delete(lineBear)
    lineBear := line.new(x1=bar_index - 1, y1=open, x2=bar_index + 2, y2=open, color=color.red)
    lineBearBar := bar_index



//

//IBS
ibsBullThreshold  = input(title = "IBS Bull", defval = 31)
ibsBearThreshold  = input(title = "IBS Bear", defval = 69)

isPerfectdoji = close == open

iBS = ((close - low) / (high - low)) * 100

//IBS qualifier

bullclose_ok_ibs = bullBar and iBS > i_bullIBSfactor
bearclose_ok_ibs = bearBar and iBS < I_bearIBSfactor

//Show urgent bars

bar_range = math.abs(high - low)
isbull = close > open
isbear = close < open
body_size = isbull? math.abs(close-open) : isbear ? math.abs(open-close) : na
bodyoverrange = body_size / bar_range

toptail = isbull? high - close : isbear? high - open : na
bottomtail = isbull? open - low : isbear? close - low : na
toptailoverbarrange = toptail / bar_range
bottomtailoverbarrange = bottomtail / bar_range
bigenoughbody = bodyoverrange > (BodyRangeThreshold / 100)


urgentbull = isbull and bottomtailoverbarrange < (UrgencyBullThreshold / 100) and bigenoughbody
urgentbear = isbear and toptailoverbarrange < (UrgencyBearThreshold / 100) and bigenoughbody

ploturgentbull = urgentbull and plotUrgentBars == true
ploturgentbear = urgentbear and plotUrgentBars == true


plotshape(ploturgentbull, "Urgent bulls", style=shape.arrowup, location=location.belowbar, color=color.rgb(33, 149, 243, 47))

plotshape(ploturgentbear, "Urgent bears", style=shape.arrowdown, location=location.abovebar, color=color.rgb(255, 82, 82, 47))

ploturgentclarity_bl = ploturgentbull and bulltickgap and plotClarityBars == true
ploturgentclarity_br = ploturgentbear and beartickgap and plotClarityBars == true

barcolor(ploturgentclarity_bl? color.blue : ploturgentclarity_br? color.red : na)

//Avg Bar Range Lookback

lookbackPeriod = input(8, "Lookback Period")

averageBarRange = math.sum(bar_range, lookbackPeriod) / lookbackPeriod
scalp_trend = averageBarRange * 0.8
scalp_countertrend = averageBarRange * 0.8 * 0.5

//Plots
//plot(iBS, "ibs" )
//plot(bar_range, "bar range")
//plot(body_size, "body size")
//plot(bodyoverrange, "body %")
//plot(averageBarRange, "Average Bar Range")
//plot(scalp_trend, "scalp trend")
//plot(scalp_countertrend, "scalp countertrend")

Overview

Zen Gaps v5.0 detects bullish gaps when the current low exceeds the prior bar's high and bearish gaps when the current high falls below the prior bar's low. Strong gaps receive extra emphasis when consecutive bars maintain the same directional status. The script also plots vertical lines for tick gaps when enabled. Inputs allow toggling display of tick gaps, urgent bars, and clarity bars, along with thresholds for IBS factors, urgency percentages, body range limits, and custom colors for bullish, bearish, and strong gap types. Boxes appear directly on the chart without additional panes.

Details

Published by

Zen-Tim on GitHub

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Support & resistance, Candlestick patterns

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Show Tick Gaps ?stringOnplotTickGaps
Show Urgent Bars ?stringOnplotUrgentBars
Show Clarity?stringOnplotClarityBars
Bull IBS Thresholdint69i_bullIBSfactor
Bear INS Thresholdint31I_bearIBSfactor
Urgency Bull %int15UrgencyBullThreshold
Urgency Bear %int15UrgencyBearThreshold
Body Range Limitint51BodyRangeThreshold
Bullish Gap Backgroundcolorcolor.rgb(76, 175, 79, 95)bullGapBGColor
Bullish Gap Bordercolorcolor.rgb(76, 175, 79, 100)bullGapBorderColor
Strongly Bullish Gap Backgroundcolorcolor.rgb(55, 188, 255, 80)strongBullGapBGColor
Strongly Bullish Gap Bordercolorcolor.rgb(66, 116, 187, 100)strongBullGapBorderColor
Show all 19 settings
SettingTypeDefaultVariable
Bearish Gap Backgroundcolorcolor.rgb(255, 82, 82, 92)bearGapBGColor
Bearish Gap Bordercolorcolor.rgb(255, 82, 82, 100)bearGapBorderColor
Strongly Bearish Gap Backgroundcolorcolor.rgb(55, 188, 255, 80)strongBearGapBGColor
Strongly Bearish Gap Bordercolorcolor.rgb(66, 116, 187, 100)strongBearGapBorderColor
IBS Bullint31ibsBullThreshold
IBS Bearint69ibsBearThreshold
Lookback Periodint8lookbackPeriod
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

[RS]MTF Candle Sticks

by ricardosantos79
261 stars

This indicator overlays up to five higher-timeframe candlestick groups on the price chart. For each enabled timeframe it requests open, high, low, and close and can show up to five candles, offset by a spacing setting. The main inputs set the candle count, the

Indicator v4 Candlestick patternsSupport & resistance Repaints
Updated 4 years ago · None stated GitHub repository of [RS]MTF Candle Sticks

Candlestick Patterns

by harryguiacorn
219 stars

This indicator plots optional candlestick pattern signals on the price chart. It detects engulfing bars, inside bars, HOLP and LOHP, kicker patterns, body-mass extremes, higher highs and lower lows, ATR warnings, and four-bar fractals. Optional pivot marks use

Indicator v5 Candlestick patternsVolatility & bands
Updated 1 year ago · None stated GitHub repository of Candlestick Patterns

Strat Assistant

by rickyzcarroll
90 stars

The Strat Assistant indicator identifies candlestick patterns from the STRAT methodology on the price chart. It detects inside bars, 2-candle directional bars, 3-candle outside bars, and sequences like 212 and 222 for continuations and reversals. Shapes such a

Indicator v4 Candlestick patternsSupport & resistance
Updated 5 years ago · None stated GitHub repository of Strat Assistant
56 stars

This overlay indicator highlights candles with a body smaller than 50% of their total range by coloring them white on the price chart. Simultaneously, it calculates and plots horizontal lines for open prices across multiple higher timeframes, such as daily, we

Indicator v6 Support & resistanceCandlestick patterns Repaints
Updated 2 months ago · None stated GitHub repository of Daily Weekly Monthly Yearly Opens

This Pine Script indicator identifies liquidity sweeps and confirms signals using a close-back candle pattern directly on the price chart. It tracks recent swing highs and lows over a customizable lookback period. A bullish signal forms when a prior bar sweeps

Indicator v6 SMC / ICT / price actionSupport & resistance
Updated 2 months ago · MPL-2.0 GitHub repository of Liquidity Sweep + Close-Back Confirmation

8020 System Indicator

by TamaraKGreen
46 stars

This overlay indicator draws 80/20 price levels and optional 40-point zone bands on the price chart. It marks repairs, cross sections, and forks with optional letter labels, and can highlight confluence when those marks sit near a level. Separate options shade

Indicator v6 Support & resistanceCandlestick patterns
Updated 7 weeks ago · None stated GitHub repository of 8020 System Indicator

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers