Indicator · Pine Script v5 · On the chart

Daily Segment Probabilities

by TamaraKGreen· code credited to lucymatos

Daily Segment Probabilities is an overlay indicator that lays out twelve percentage bands around the previous day's high and low, from 100 percent below that range to 200 percent above it, in 25 percent steps.

View on GitHub

GitHub stars46on the repository
Pine versionv5runs as is
Lines of code309
Settings13inputs
LicenceNone statedfile: MPL-2.0
Last update7 weeks ago4 Sep 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

309 lines of Pine Script v5 from Daily High Low probability zones.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Daily High Low probability zones.txt
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © lucymatos

//@version=5
indicator("Daily Segment Probabilities", shorttitle="DSP", overlay=true, max_lines_count=500, max_labels_count=500)

// ─────────────────────────────────────────────────────────────────────────────
// INPUTS
// ─────────────────────────────────────────────────────────────────────────────
grpMain = "Core Settings"
grpVis  = "Visual Settings"
grpTbl  = "Table Settings"

lookback = input.int(250, "Lookback (days)", minval=10, maxval=500, group=grpMain)

int   N_SEGS = 12
var segEdges = array.new_float(13)
array.set(segEdges,  0, -100.0)
array.set(segEdges,  1,  -75.0)
array.set(segEdges,  2,  -50.0)
array.set(segEdges,  3,  -25.0)
array.set(segEdges,  4,    0.0)
array.set(segEdges,  5,   25.0)
array.set(segEdges,  6,   50.0)
array.set(segEdges,  7,   75.0)
array.set(segEdges,  8,  100.0)
array.set(segEdges,  9,  125.0)
array.set(segEdges, 10,  150.0)
array.set(segEdges, 11,  175.0)
array.set(segEdges, 12,  200.0)

var segLabels = array.new_string(12)
array.set(segLabels,  0, "-100–-75%")
array.set(segLabels,  1,  "-75–-50%")
array.set(segLabels,  2,  "-50–-25%")
array.set(segLabels,  3,   "-25–0%")
array.set(segLabels,  4,    "0–25%")
array.set(segLabels,  5,   "25–50%")
array.set(segLabels,  6,   "50–75%")
array.set(segLabels,  7,  "75–100%")
array.set(segLabels,  8, "100–125%")
array.set(segLabels,  9, "125–150%")
array.set(segLabels, 10, "150–175%")
array.set(segLabels, 11, "175–200%")

// ── Zone colours (user-configurable) ─────────────────────────────────────────
pdhlColor    = input.color(color.new(#2962FF, 0),   "PDH/PDL line colour",            group=grpVis)
colInside    = input.color(color.new(#26A69A, 0),   "Inside range colour (0–100%)",   group=grpVis)
colAbove     = input.color(color.new(#5C6BC0, 0),   "Extension above colour (>100%)", group=grpVis)
colBelow     = input.color(color.new(#EF5350, 0),   "Extension below colour (<0%)",   group=grpVis)
lblColor     = input.color(color.new(#787B86, 0),   "Label text colour",              group=grpVis)
segStyle     = input.string("Dashed (╌)", "Segment line style",
     options=["Solid (─)", "Dotted (┈)", "Dashed (╌)"], group=grpVis)
pdhlStyle    = input.string("Solid (─)", "PDH/PDL line style",
     options=["Solid (─)", "Dotted (┈)", "Dashed (╌)"], group=grpVis)
colHighFill  = input.color(color.new(#FFD700, 60),  "Top High% band fill colour",     group=grpVis)
colLowFill   = input.color(color.new(#FF6B35, 60),  "Top Low% band fill colour",      group=grpVis)

showTable     = input.bool(true, "Show probability table", group=grpTbl)
tablePos      = input.string("Top Right", "Table position",
     options=["Top Right","Bottom Right","Middle Right","Bottom Center","Middle Left"], group=grpTbl)
tableTextSize = input.string("Small", "Table text size",
     options=["Auto","Tiny","Small","Normal","Large","Huge"], group=grpTbl)

// ─────────────────────────────────────────────────────────────────────────────
// HELPERS
// ─────────────────────────────────────────────────────────────────────────────
lnStyle(s) =>
    s == "Dotted (┈)" ? line.style_dotted : s == "Dashed (╌)" ? line.style_dashed : line.style_solid

tblPos(p) =>
    switch p
        "Top Right"     => position.top_right
        "Bottom Right"  => position.bottom_right
        "Middle Right"  => position.middle_right
        "Bottom Center" => position.bottom_center
        "Middle Left"   => position.middle_left

tblSz(s) =>
    switch s
        "Auto"   => size.auto
        "Tiny"   => size.tiny
        "Small"  => size.small
        "Normal" => size.normal
        "Large"  => size.large
        "Huge"   => size.huge

pctToPrice(pdLow, pdRange, pct) =>
    pdLow + pdRange * (pct / 100.0)

getSegIdx(pct) =>
    idx = -1
    for k = 0 to N_SEGS - 1
        lo = array.get(segEdges, k)
        hi = array.get(segEdges, k + 1)
        if k == N_SEGS - 1
            if pct >= lo and pct <= hi
                idx := k
        else
            if pct >= lo and pct < hi
                idx := k
    idx

segZoneColor(k) =>
    k >= 8 ? colAbove : k >= 4 ? colInside : colBelow

segRowBg(k) =>
    k >= 8 ? color.new(colAbove, 82) : k >= 4 ? color.new(colInside, 82) : color.new(colBelow, 82)

// ─────────────────────────────────────────────────────────────────────────────
// FETCH DAILY H/L
// ─────────────────────────────────────────────────────────────────────────────
get_daily(bars) =>
    h = array.new_float(0)
    l = array.new_float(0)
    t = array.new_int(0)
    for n = 0 to bars
        array.push(h, high[n])
        array.push(l, low[n])
        array.push(t, time[n])
    [h, l, t]

[dHighs, dLows, dTimes] = request.security(syminfo.tickerid, "1D",
     get_daily(lookback + 1), lookahead=barmerge.lookahead_off)

// ─────────────────────────────────────────────────────────────────────────────
// ALL LOGIC ON LAST BAR ONLY
// ─────────────────────────────────────────────────────────────────────────────
if bar_index == last_bar_index

    segHighCounts = array.new_int(N_SEGS, 0)
    segLowCounts  = array.new_int(N_SEGS, 0)
    highOutAbove  = 0
    highOutBelow  = 0
    lowOutAbove   = 0
    lowOutBelow   = 0
    n = 0

    for i = 1 to math.min(lookback, array.size(dHighs) - 2)
        priorHigh  = array.get(dHighs, i + 1)
        priorLow   = array.get(dLows,  i + 1)
        priorRange = priorHigh - priorLow
        if priorRange > 0
            dayHigh = array.get(dHighs, i)
            dayLow  = array.get(dLows,  i)
            hPct    = (dayHigh - priorLow) / priorRange * 100.0
            lPct    = (dayLow  - priorLow) / priorRange * 100.0
            hIdx    = getSegIdx(hPct)
            lIdx    = getSegIdx(lPct)
            if hIdx >= 0
                array.set(segHighCounts, hIdx, array.get(segHighCounts, hIdx) + 1)
            else if hPct > 200.0
                highOutAbove += 1
            else
                highOutBelow += 1
            if lIdx >= 0
                array.set(segLowCounts, lIdx, array.get(segLowCounts, lIdx) + 1)
            else if lPct > 200.0
                lowOutAbove += 1
            else
                lowOutBelow += 1
            n += 1

    if n >= 5
        pdHigh     = array.get(dHighs, 1)
        pdLow      = array.get(dLows,  1)
        pdRange    = pdHigh - pdLow
        todayStart = array.get(dTimes, 0)
        todayEnd   = todayStart + 86400000

        // ── Find top High% and Low% segments ─────────────────────────────────
        topHighSeg = 0
        topHighVal = array.get(segHighCounts, 0)
        topLowSeg  = 0
        topLowVal  = array.get(segLowCounts, 0)

        for k = 1 to N_SEGS - 1
            hc = array.get(segHighCounts, k)
            lc = array.get(segLowCounts,  k)
            if hc > topHighVal
                topHighVal := hc
                topHighSeg := k
            if lc > topLowVal
                topLowVal := lc
                topLowSeg := k

        // ── Rest of logic gated on pdRange ────────────────────────────────────
        if pdRange > 0

            // ── Band fills ───────────────────────────────────────────────────
            highFillLo = pctToPrice(pdLow, pdRange, array.get(segEdges, topHighSeg))
            highFillHi = pctToPrice(pdLow, pdRange, array.get(segEdges, topHighSeg + 1))
            hFillBot   = line.new(todayStart, highFillLo, todayEnd, highFillLo,
                 xloc=xloc.bar_time, color=color.new(color.white, 100), width=1)
            hFillTop   = line.new(todayStart, highFillHi, todayEnd, highFillHi,
                 xloc=xloc.bar_time, color=color.new(color.white, 100), width=1)
            linefill.new(hFillBot, hFillTop, color=colHighFill)

            if topLowSeg != topHighSeg
                lowFillLo = pctToPrice(pdLow, pdRange, array.get(segEdges, topLowSeg))
                lowFillHi = pctToPrice(pdLow, pdRange, array.get(segEdges, topLowSeg + 1))
                lFillBot  = line.new(todayStart, lowFillLo, todayEnd, lowFillLo,
                     xloc=xloc.bar_time, color=color.new(color.white, 100), width=1)
                lFillTop  = line.new(todayStart, lowFillHi, todayEnd, lowFillHi,
                     xloc=xloc.bar_time, color=color.new(color.white, 100), width=1)
                linefill.new(lFillBot, lFillTop, color=colLowFill)

            // ── PDH and PDL lines ─────────────────────────────────────────────
            line.new(todayStart, pdHigh, todayEnd, pdHigh,
                 xloc=xloc.bar_time, color=pdhlColor,
                 style=lnStyle(pdhlStyle), width=2)
            label.new(todayEnd, pdHigh, text="PDH: " + str.tostring(pdHigh, "#.00"),
                 xloc=xloc.bar_time, color=color.new(color.black, 100),
                 textcolor=pdhlColor, size=size.small,
                 style=label.style_label_left,
                 text_font_family=font.family_monospace)

            line.new(todayStart, pdLow, todayEnd, pdLow,
                 xloc=xloc.bar_time, color=pdhlColor,
                 style=lnStyle(pdhlStyle), width=2)
            label.new(todayEnd, pdLow, text="PDL: " + str.tostring(pdLow, "#.00"),
                 xloc=xloc.bar_time, color=color.new(color.black, 100),
                 textcolor=pdhlColor, size=size.small,
                 style=label.style_label_left,
                 text_font_family=font.family_monospace)

            // ── Segment boundary lines ────────────────────────────────────────
            for k = 0 to N_SEGS
                edgePct   = array.get(segEdges, k)
                if edgePct != 0.0 and edgePct != 100.0
                    segIdx    = math.min(k, N_SEGS - 1)
                    edgeColor = segZoneColor(segIdx)
                    edgePrice = pctToPrice(pdLow, pdRange, edgePct)
                    line.new(todayStart, edgePrice, todayEnd, edgePrice,
                         xloc=xloc.bar_time, color=edgeColor,
                         style=lnStyle(segStyle), width=1)

            // ── Segment midpoint labels ───────────────────────────────────────
            for k = 0 to N_SEGS - 1
                loPct    = array.get(segEdges, k)
                hiPct    = array.get(segEdges, k + 1)
                midPrice = pctToPrice(pdLow, pdRange, (loPct + hiPct) / 2.0)
                hCount   = array.get(segHighCounts, k)
                lCount   = array.get(segLowCounts,  k)
                hPctLbl  = math.round(float(hCount) / n * 100)
                lPctLbl  = math.round(float(lCount) / n * 100)
                segLbl   = array.get(segLabels, k)
                hStar    = k == topHighSeg ? " ★H" : ""
                lStar    = k == topLowSeg  ? " ★L" : ""
                labelTxt = segLbl + "  H:" + str.tostring(hPctLbl) + "%" + hStar + "  L:" + str.tostring(lPctLbl) + "%" + lStar
                label.new(todayEnd, midPrice,
                     text=labelTxt,
                     xloc=xloc.bar_time,
                     color=color.new(color.black, 100),
                     textcolor=lblColor,
                     size=size.small,
                     style=label.style_label_left,
                     text_font_family=font.family_monospace,
                     tooltip=segLbl + "\n" +
                             "High formed here: " + str.tostring(hCount) + "/" + str.tostring(n) + " days (" + str.tostring(hPctLbl) + "%)\n" +
                             "Low  formed here: " + str.tostring(lCount) + "/" + str.tostring(n) + " days (" + str.tostring(lPctLbl) + "%)")

        // ── TABLE ─────────────────────────────────────────────────────────────
        if showTable
            tblRows = N_SEGS + 3
            tbl = table.new(tblPos(tablePos), 4, tblRows,
                 border_width=1,
                 border_color=color.new(color.gray, 60),
                 frame_color=color.new(color.gray, 60),
                 frame_width=1,
                 bgcolor=color.white)

            sz      = tblSz(tableTextSize)
            hdrBg   = color.new(color.gray, 70)
            hdrTxt  = color.black
            cellTxt = color.black

            table.cell(tbl, 0, 0, "Seg",    bgcolor=hdrBg, text_color=hdrTxt, text_size=sz, text_font_family=font.family_monospace)
            table.cell(tbl, 1, 0, "Range",  bgcolor=hdrBg, text_color=hdrTxt, text_size=sz, text_font_family=font.family_monospace)
            table.cell(tbl, 2, 0, "High %", bgcolor=hdrBg, text_color=hdrTxt, text_size=sz, text_font_family=font.family_monospace)
            table.cell(tbl, 3, 0, "Low %",  bgcolor=hdrBg, text_color=hdrTxt, text_size=sz, text_font_family=font.family_monospace)

            for k = 0 to N_SEGS - 1
                row    = k + 1
                hCount = array.get(segHighCounts, k)
                lCount = array.get(segLowCounts,  k)
                hPct   = math.round(float(hCount) / n * 100)
                lPct   = math.round(float(lCount) / n * 100)
                rowBg  = segRowBg(k)
                hBg    = k == topHighSeg ? colHighFill : rowBg
                lBg    = k == topLowSeg  ? colLowFill  : rowBg
                table.cell(tbl, 0, row, str.tostring(k + 1),     bgcolor=rowBg, text_color=cellTxt, text_size=sz, text_font_family=font.family_monospace)
                table.cell(tbl, 1, row, array.get(segLabels, k), bgcolor=rowBg, text_color=cellTxt, text_size=sz, text_font_family=font.family_monospace)
                table.cell(tbl, 2, row, str.tostring(hPct) + "%", bgcolor=hBg,  text_color=cellTxt, text_size=sz, text_font_family=font.family_monospace)
                table.cell(tbl, 3, row, str.tostring(lPct) + "%", bgcolor=lBg,  text_color=cellTxt, text_size=sz, text_font_family=font.family_monospace)

            outRow  = N_SEGS + 1
            hOOBpct = math.round(float(highOutAbove + highOutBelow) / n * 100)
            lOOBpct = math.round(float(lowOutAbove  + lowOutBelow)  / n * 100)
            table.cell(tbl, 0, outRow, "OOB",                        bgcolor=color.new(colBelow, 82), text_color=cellTxt, text_size=sz, text_font_family=font.family_monospace)
            table.cell(tbl, 1, outRow, "<-100%/>200%",               bgcolor=color.new(colBelow, 82), text_color=cellTxt, text_size=sz, text_font_family=font.family_monospace)
            table.cell(tbl, 2, outRow, str.tostring(hOOBpct) + "%",  bgcolor=color.new(colBelow, 82), text_color=cellTxt, text_size=sz, text_font_family=font.family_monospace)
            table.cell(tbl, 3, outRow, str.tostring(lOOBpct) + "%",  bgcolor=color.new(colBelow, 82), text_color=cellTxt, text_size=sz, text_font_family=font.family_monospace)

            nRow = N_SEGS + 2
            table.cell(tbl, 0, nRow, "n=" + str.tostring(n),         bgcolor=hdrBg, text_color=hdrTxt, text_size=sz, text_font_family=font.family_monospace)
            table.cell(tbl, 1, nRow, str.tostring(lookback) + "d lb", bgcolor=hdrBg, text_color=hdrTxt, text_size=sz)
            table.cell(tbl, 2, nRow, "",                               bgcolor=hdrBg, text_color=hdrTxt, text_size=sz)
            table.cell(tbl, 3, nRow, "",                               bgcolor=hdrBg, text_color=hdrTxt, text_size=sz)

Overview

Daily Segment Probabilities draws previous-day high and low lines and segment boundaries with selectable solid, dotted, or dashed styles, and fills the top high-percent and low-percent bands. The lookback sets how many days are used. An optional table shows segment probabilities, with position and text size controls. It has no trade entries or exits.

Details

Published by

TamaraKGreen on GitHub

Code credit

lucymatos, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Support & resistance, Screeners & dashboards

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
Lookback (days)int250lookback
PDH/PDL line colourcolorcolor.new(#2962FF, 0)pdhlColor
Inside range colour (0–100%)colorcolor.new(#26A69A, 0)colInside
Extension above colour (>100%)colorcolor.new(#5C6BC0, 0)colAbove
Extension below colour (<0%)colorcolor.new(#EF5350, 0)colBelow
Label text colourcolorcolor.new(#787B86, 0)lblColor
Segment line stylestringDashed (╌)segStyle
PDH/PDL line stylestringSolid (─)pdhlStyle
Top High% band fill colourcolorcolor.new(#FFD700, 60)colHighFill
Top Low% band fill colourcolorcolor.new(#FF6B35, 60)colLowFill
Show probability tablebooltrueshowTable
Table positionstringTop RighttablePos
Show all 13 settings
SettingTypeDefaultVariable
Table text sizestringSmalltableTextSize
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

575 stars

This overlay indicator scans a pasted list of symbols for ICT liquidity sweep patterns using prior swing sweeps. The screening method looks back one, two, or three swings and can list long and short signals in a results table with adjustable rows, position, an

Indicator v5 SMC / ICT / price actionScreeners & dashboards
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Liquidity Sweep Pattern Scanner
330 stars

This indicator monitors multiple cryptocurrency symbols for trading signals. It calculates and plots entry prices, take profit, and stop loss levels for each symbol including BTCUSDT, ETHUSDT, BNBUSDT and others. Price crossovers trigger buy, sell or close ale

Indicator v5 Support & resistanceScreeners & dashboards
Updated 2 months ago · None stated GitHub repository of Multi Alert Long/Short [Alorse]

BZ-tracker

by Allen1212
303 stars

The BZ-tracker indicator marks ARK Invest buy and sell transactions on stock charts with labels. It plots green labels for purchases and red labels for sales, each annotated with a multiplier such as X1 or X2 to show the number of ARK ETFs trading the stock on

Indicator v4 Support & resistanceScreeners & dashboards
Updated 2 years ago · None stated GitHub repository of BZ-tracker
257 stars

This indicator overlays an intraday SPX and ES chart with a midnight session range, regular-trading-hours opening levels, and a VWAP projection box. It draws the midnight high, mid, and low, flags edge rejections within an absolute tolerance, and plots optiona

Indicator v6 TrendSupport & resistance
Updated 6 weeks ago · None stated GitHub repository of SPX Midnight Box + Snag Logic

Golden Bullet Strategy

by TradersPost
218 stars

The Golden Bullet Strategy is an overlay signal indicator based on Smart Money Concepts and time-based liquidity models. It identifies liquidity sweeps of a designated reference session range during a specified hunt window. It then confirms Market Structure Sh

Indicator v6 SMC / ICT / price actionSessions & time
Updated 3 months ago · None stated GitHub repository of Golden Bullet Strategy

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