Indicator · Pine Script v6 · On the chart

GridWB3 V7

by cckmchiu-gapps· code credited to ekmchiu

This indicator draws a price and time grid on the price chart that scales itself in one of two modes.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code139
Settings13inputs
LicenceNone statedfile: MPL-2.0
Last update7 days ago22 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

139 lines of Pine Script v6 from GridWB3_v7.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

GridWB3_v7.txt
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ekmchiu

//@version=6
indicator("GridWB3 V7", "GridWB3 V7", overlay = true, max_lines_count = 500, max_boxes_count = 50)

// --- Inputs ---
grpScale   = "Auto-Scaling Mode"
scaleMode  = input.string("Full Visible Screen", "Scaling Mode", options = ["Full Visible Screen", "Fixed Historical Dates"], group = grpScale)
autoGrids  = input.int(3, "Grids Count", minval = 1, maxval = 7, group = grpScale)

grpCalc    = "Fixed Date Settings (Used if Mode = Fixed Historical Dates)"
startDate  = input.time(timestamp("2024-12-20 00:00:00 +0800"), "Start Date", group = grpCalc)
endDate    = input.time(timestamp("2027-12-17 00:00:00 +0800"), "End Date", group = grpCalc)

// --- Style Inputs ---
edgeAdjust = input.int(0, "Fine-tune right edge (bars)", minval = -10, maxval = 10, group = "Grid")
gridCol    = input.color(color.new(color.blue, 0),  "Color A (grid 0,2,4...)", group = "Style")
altCol     = input.color(color.new(color.red, 0),   "Color B (grid 1,3,5...)", group = "Style")
diagCol    = input.color(color.new(color.blue, 0),  "Slope color",            group = "Style")
fillCol    = input.color(color.new(color.gray, 92), "Box fill",               group = "Style")
gridTransp = input.int(40, "Grid transparency", minval = 0, maxval = 100, group = "Style")
diagTransp = input.int(40, "Slope transparency", minval = 0, maxval = 100, group = "Style")
gridW      = input.int(1, "Grid width",  minval = 1, maxval = 4, group = "Style")
diagW      = input.int(1, "Slope width", minval = 1, maxval = 4, group = "Style")

// Apply transparency
colGrid = color.new(gridCol, gridTransp)
colAlt  = color.new(altCol,  gridTransp)
colDiag = color.new(diagCol, diagTransp)

// --- Track Bar Indices for Visible Screen ---
int visLeftBar  = ta.valuewhen(time <= chart.left_visible_bar_time, bar_index, 0)
int visRightBar = ta.valuewhen(time <= chart.right_visible_bar_time, bar_index, 0)

// --- Execution on Last Bar ---
if barstate.islast
    int biL = 0
    int biR = 0
    float pTop = 0.0
    float pBot = 0.0

    if scaleMode == "Full Visible Screen"
        // Get visible bar index boundaries
        biL := na(visLeftBar) ? 0 : visLeftBar
        biR := (na(visRightBar) ? bar_index : visRightBar) + edgeAdjust

        // Calculate highest high and lowest low across the visible range
        int visibleBars = math.max(1, bar_index - biL + 1)
        pTop := ta.highest(high, visibleBars)
        pBot := ta.lowest(low, visibleBars)
    else
        // Fallback to historical date calculations
        biL := ta.valuewhen(time <= startDate, bar_index, 0)
        biR := ta.valuewhen(time <= endDate, bar_index, 0)
        if endDate > time
            biR := bar_index + int(math.round((endDate - time) / (timeframe.in_seconds() * 1000.0))) + edgeAdjust
        
        int spanBars = math.max(1, bar_index - biL + 1)
        pTop := ta.highest(high, spanBars)
        pBot := ta.lowest(low, spanBars)

    float dh = pTop - pBot
    int span = biR - biL

    // Outer box
    box.new(biL, pTop, biR, pBot,
         border_color = colGrid, border_width = gridW, bgcolor = fillCol,
         xloc = xloc.bar_index)

    // Unit boundaries
    if autoGrids > 1
        for i = 1 to autoGrids - 1
            int bx = biL + int(math.round(span * i / float(autoGrids)))
            line.new(bx, pTop, bx, pBot, xloc = xloc.bar_index, color = colGrid, width = gridW)

    // Per unit grid & slopes
    for i = 0 to autoGrids - 1
        int xL = biL + int(math.round(span * i / float(autoGrids)))
        int xR = biL + int(math.round(span * (i + 1) / float(autoGrids)))
        int wu = xR - xL

        int q1 = xL + int(math.round(wu * 0.25))
        int q2 = xL + int(math.round(wu * 0.50))
        int q3 = xL + int(math.round(wu * 0.75))
        int xM = q2

        lineCol = i % 2 == 0 ? colGrid : colAlt

        float yB = pBot
        float yT = pTop
        float yM = pBot + dh * 0.5

        // Horizontal lines
        line.new(xL, pBot + dh * 0.25, xR, pBot + dh * 0.25, xloc = xloc.bar_index, color = lineCol, width = gridW)
        line.new(xL, pBot + dh * 0.5,  xR, pBot + dh * 0.5,  xloc = xloc.bar_index, color = lineCol, width = gridW)
        line.new(xL, pBot + dh * 0.75, xR, pBot + dh * 0.75, xloc = xloc.bar_index, color = lineCol, width = gridW)

        // Vertical lines
        line.new(q1, pTop, q1, pBot, xloc = xloc.bar_index, color = lineCol, width = gridW)
        line.new(q2, pTop, q2, pBot, xloc = xloc.bar_index, color = lineCol, width = gridW)
        line.new(q3, pTop, q3, pBot, xloc = xloc.bar_index, color = lineCol, width = gridW)

        // Slopes
        line.new(xL, yT, xM, yB, xloc = xloc.bar_index, color = colDiag, width = diagW)
        line.new(xL, yT, xR, yM, xloc = xloc.bar_index, color = colDiag, width = diagW)
        line.new(xL, yT, xR, yB, xloc = xloc.bar_index, color = colDiag, width = diagW)
        line.new(xL, yB, xM, yT, xloc = xloc.bar_index, color = colDiag, width = diagW)
        line.new(xL, yB, xR, yM, xloc = xloc.bar_index, color = colDiag, width = diagW)
        line.new(xL, yB, xR, yT, xloc = xloc.bar_index, color = colDiag, width = diagW)
        line.new(xR, yT, xM, yB, xloc = xloc.bar_index, color = colDiag, width = diagW)
        line.new(xR, yT, xL, yM, xloc = xloc.bar_index, color = colDiag, width = diagW)
        line.new(xR, yT, xL, yB, xloc = xloc.bar_index, color = colDiag, width = diagW)
        line.new(xR, yB, xM, yT, xloc = xloc.bar_index, color = colDiag, width = diagW)
        line.new(xR, yB, xL, yM, xloc = xloc.bar_index, color = colDiag, width = diagW)
        line.new(xR, yB, xL, yT, xloc = xloc.bar_index, color = colDiag, width = diagW)

    // --- Bottom-Left Info Table ---
    var table infoTable = table.new(position = position.bottom_right, columns = 2, rows = 6, 
                                    bgcolor = color.new(color.yellow, 20), 
                                    border_width = 1, border_color = color.gray)
    
    table.cell(infoTable, 0, 0, "Param", bgcolor = color.navy, text_color = color.white, text_size = size.small)
    table.cell(infoTable, 1, 0, syminfo.ticker + " (" + scaleMode + ")", bgcolor = color.navy, text_color = color.white, text_size = size.small)

    table.cell(infoTable, 0, 1, "Left Bar / Start", text_color = color.gray, text_size = size.small)
    table.cell(infoTable, 1, 1, str.tostring(biL), text_color = color.white, text_size = size.small)

    table.cell(infoTable, 0, 2, "High Price (p1)", text_color = color.gray, text_size = size.small)
    table.cell(infoTable, 1, 2, str.tostring(pTop, "#.##"), text_color = color.green, text_size = size.small)

    table.cell(infoTable, 0, 3, "Right Bar / End", text_color = color.gray, text_size = size.small)
    table.cell(infoTable, 1, 3, str.tostring(biR), text_color = color.white, text_size = size.small)

    table.cell(infoTable, 0, 4, "Low Price (p2)", text_color = color.gray, text_size = size.small)
    table.cell(infoTable, 1, 4, str.tostring(pBot, "#.##"), text_color = color.red, text_size = size.small)

    table.cell(infoTable, 0, 5, "Grids Count", text_color = color.gray, text_size = size.small)
    table.cell(infoTable, 1, 5, str.tostring(autoGrids), text_color = color.yellow, text_size = size.small)

Overview

Full Visible Screen uses the highest high and lowest low of the bars currently on screen, while Fixed Historical Dates uses a chosen start and end date. The box is divided into one to seven alternating-colour units with diagonal lines. A bar offset adjusts the right edge, and colours, transparency and widths are adjustable. It is a drawing aid and gives no signals.

Details

Published by

cckmchiu-gapps on GitHub

Code credit

ekmchiu, as written in the script's header

Type

Indicator, Pine Script v6

Draws

On the price chart

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
Scaling ModestringFull Visible ScreenscaleMode
Grids Countint3autoGrids
Start Datetimetimestamp("2024-12-20 00:00:00 +0800")startDate
End Datetimetimestamp("2027-12-17 00:00:00 +0800")endDate
Fine-tune right edge (bars)int0edgeAdjust
Color A (grid 0,2,4...)colorcolor.new(color.blue, 0)gridCol
Color B (grid 1,3,5...)colorcolor.new(color.red, 0)altCol
Slope colorcolorcolor.new(color.blue, 0)diagCol
Box fillcolorcolor.new(color.gray, 92)fillCol
Grid transparencyint40gridTransp
Slope transparencyint40diagTransp
Grid widthint1gridW
Show all 13 settings
SettingTypeDefaultVariable
Slope widthint1diagW
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

948 stars

The Adaptive Laguerre Filter calculates a smoothed, dynamically adjusted trendline plotted directly on the main price chart. It dynamically adjusts its damping factor (alpha) based on recent price range variations and median percentile calculations over a spec

Indicator v4 TrendMoving averages
Updated 11 days ago · GPL-3.0 GitHub repository of Adaptive Laguerre Filter
575 stars

The indicator plots ICT displacement candles on the price chart and can switch to retracement scanning. Displacement requires a move larger than a set share of the 14-bar average high-low range, lasting at least a chosen number of bars, with optional close, pr

Indicator v6 SMC / ICT / price actionCandlestick patterns
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Displacement Candles Indicator
330 stars

This script plots three moving averages on the price chart: a fast EMA or SMA with 10 periods, a slow EMA or SMA with 20 periods, and a trend EMA or SMA with 100 periods. It signals trend changes by drawing a white cross when the fast moving average crosses ab

Indicator v4 TrendMoving averages
Updated 2 months ago · None stated GitHub repository of 3 EMA/SMA + Cross [Alorse]
318 stars

This indicator calculates an ATR trailing stop line derived from the highest high minus an average true range multiple over a specified lookback period. It plots the trailing stop line directly on the price chart and colors price bars based on whether the clos

Indicator v5 TrendVolatility & bands
Updated 2 months ago · MIT GitHub repository of ATR Trailing Stoploss

1833 Tracker

by Allen1212
303 stars

1833 Tracker is an overlay indicator that visualizes historical buy and sell transactions executed by ARK Invest ETFs for the stock on the main price chart. It displays trade dates using green buy and red sell labels positioned relative to price bars, indicati

Indicator v4
Updated 2 years ago · None stated GitHub repository of 1833 Tracker

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