Indicator · Pine Script v6 · On the chart

GridWB3 Auto-Calculated Config

by cckmchiu-gapps· code credited to ekmchiu

This indicator draws a price and time grid on the price chart and sets its anchors automatically.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code141
Settings12inputs
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

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

GridWB3_v5.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 Auto-Calculated Config", "GridWB3 Auto", overlay = true, max_lines_count = 500, max_boxes_count = 50)

// --- Struct Definition ---
type SymbolConfig
    int   t1
    float p1
    int   t2
    float p2
    int   grids

// --- Function to Calculate Anchors Dynamically ---
getDynamicConfig(int startTime, int endTime, int defaultGrids) =>
    var float maxClose = na
    var float minClose = na
    
    // Scan historical bars starting from the start time
    if time >= startTime
        if na(maxClose) or close > maxClose
            maxClose := close
        if na(minClose) or close < minClose
            minClose := close

    // Fallbacks if data before startTime is incomplete
    float safeP1 = na(maxClose) ? high : maxClose
    float safeP2 = na(minClose) ? low  : minClose
    
    SymbolConfig.new(endTime, safeP1, startTime, safeP2, defaultGrids)

// --- Dynamic Date Inputs ---
grpCalc   = "Auto-Calculation Settings"
startDate = input.time(timestamp("2024-12-20 00:00:00 +0800"), "Start Date (Lowest Price)", group = grpCalc)
endDate   = input.time(timestamp("2027-12-17 00:00:00 +0800"), "End Date (Target Grid Edge)", group = grpCalc)
autoGrids = input.int(3, "Grids Count", minval = 1, maxval = 7, group = grpCalc)

// --- Execute Dynamic Calculation ---
SymbolConfig cfg = getDynamicConfig(startDate, endDate, autoGrids)

int   t1    = cfg.t1
float p1    = cfg.p1
int   t2    = cfg.t2
float p2    = cfg.p2
int   grids = cfg.grids

// --- Edge Fine-Tuning & Style Inputs ---
edgeAdjust = input.int(0, "Fine-tune right edge (bars)", minval = -10, maxval = 10, group = "Grid",
     tooltip = "Shift the future right edge: -N = N bars left, +N = N bars right.")

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")

// --- Geometry ---
tLeft  = math.min(t1, t2)
tRight = math.max(t1, t2)
pTop   = math.max(p1, p2)
pBot   = math.min(p1, p2)
float dh = pTop - pBot

int biL      = ta.valuewhen(time <= tLeft,  bar_index, 0)
int biR_past = ta.valuewhen(time <= tRight, bar_index, 0)

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

// --- Drawing Logic ---
if barstate.islast

    // Right edge bar index
    int biR = biR_past
    if tRight > time
        if timeframe.in_seconds() == 86400
            int calDays  = int(math.ceil((tRight - time) / 86400000))
            int weekends = int(math.floor(calDays / 7)) * 2
            int futBars  = math.max(0, calDays - weekends + edgeAdjust - 1)
            biR := bar_index + futBars
        else
            biR := bar_index + int(math.round((tRight - time) / (timeframe.in_seconds() * 1000.0)))

    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 grids > 1
        for i = 1 to grids - 1
            int bx = biL + int(math.round(span * i / float(grids)))
            line.new(bx, pTop, bx, pBot, xloc = xloc.bar_index, color = colGrid, width = gridW)

    // Per unit grid & slopes
    for i = 0 to grids - 1
        int xL = biL + int(math.round(span * i / float(grids)))
        int xR = biL + int(math.round(span * (i + 1) / float(grids)))
        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)

Overview

GridWB3 Auto-Calculated Config scans closing prices from a chosen start date, takes the highest and lowest close as the top and bottom of the box, and uses an end date as the right edge. The box is split into one to seven side-by-side units with alternating colours and diagonal lines. A bar offset adjusts the right edge, and styling is 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

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
Start Date (Lowest Price)timetimestamp("2024-12-20 00:00:00 +0800")startDate
End Date (Target Grid Edge)timetimestamp("2027-12-17 00:00:00 +0800")endDate
Grids Countint3autoGrids
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
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

947 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

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers