Indicator · Pine Script v5 · On the chart

GG - Levels

by g-moe· code credited to goodgains

This indicator tracks and visualizes key intraday session levels directly on the price chart.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code177
Settings9inputs
LicenceNone statedfile: MPL-2.0
Last update5 months ago27 May 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

177 lines of Pine Script v5 from Tradingview/gg-levels.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

gg-levels.pine
// © goodgains

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/

//@version=5
indicator("GG - Levels", overlay = true, max_lines_count = 500, max_boxes_count = 500)

// @keywords: gg-levels, rth-session-high-low, overnight-session-high-low, initial-balance-range, prior-session-ohlc, session-vwap, session-boxes, session-lines, price-labels, yesterday-high-low, onh-onl-levels, ibh-ibl-box, est-session-times, show-lines-labels, session-ohlc-tracking, anchored-vwap, visible-bar-labels, regular-hours-levels, overnight-background, futures-session-levels

// display settings
show_lines  = input.bool(true, title = 'Show Lines', group = 'Display Settings')
show_labels = input.bool(true, title = 'Show Labels', group = 'Display Settings')

rth_color   = input.color(color.new(#5A6471, 0 ), title = 'RTH', group = 'Display Settings')
on_color    = input.color(color.new(#5A6471, 0 ), title = 'ON', group = 'Display Settings')
ibh_color   = input.color(color.new(#a5d6a7, 0), title = 'IBH', group = 'Display Settings')
ibl_color   = input.color(color.new(#faa1a4, 0), title = 'IBL', group = 'Display Settings')

// inputs
rth_session = input.session('0930-1659', title='RTH Session (EST)', group = 'Symbol Settings')
on_session = input.session('1700-0929', title='ON Session (EST)', group = 'Symbol Settings')
ib_session = input.session('0930-1030', title='IB Session (EST)', group = 'Symbol Settings')


// global vars
var int label_extension = 0


// functions
f_calculate_sess_ohlc(is_sess) =>
    var float sess_high     = na
    var float sess_low      = na
    var float sess_open     = na
    var float sess_close    = na
    sess_high     := is_sess and not is_sess[1] ? high : is_sess ? math.max(high, sess_high[1]) : sess_high[1]
    sess_low      := is_sess and not is_sess[1] ? low : is_sess ? math.min(low, sess_low[1]) : sess_low[1]
    sess_open     := is_sess and not is_sess[1] ? open : sess_open[1]
    sess_close    := not is_sess and is_sess[1] ? close : sess_close[1]

    [sess_high, sess_low, sess_open, sess_close]


f_calculate_prior_ohlc(is_sess, h, l, o, c) =>
    var float prior_high     = na
    var float prior_low      = na
    var float prior_open     = na
    var float prior_close    = na
    prior_high     := is_sess and not is_sess[1] ? h[1] : prior_high[1]
    prior_low      := is_sess and not is_sess[1] ? l[1] : prior_low[1]
    prior_open     := is_sess and not is_sess[1] ? o[1] : prior_open[1]
    prior_close    := is_sess and not is_sess[1] ? c[1] : prior_close[1]

    [prior_high, prior_low, prior_open, prior_close]
 


f_draw_line(line_value, line_active, line_color, line_width) =>
    var line line_object = na
    var int line_start = na
    
    line_start := line_active and not line_active[1] ? time : line_start[1]

    if line_active and not line_active[1]
        line_object := line.new(x1 = line_start, x2 = line_start+1, y1=line_value, y2=line_value,
         extend=extend.none, xloc = xloc.bar_time, color = line_color, width=line_width)

    else if line_active
        line.set_xy1(line_object, line_start, line_value)
        line.set_xy2(line_object, time, line_value)

    line_object


f_draw_two_box(box_top, box_bot, box_active, top_color, bot_color) =>
    var box top_box_object = na
    var box bot_box_object = na
    var int box_start = na
    var float box_mid = na
    
    box_start := box_active and not box_active[1] ? time : box_start[1]
    box_mid := math.round_to_mintick(box_top+box_bot) / 2

    if box_active and not box_active[1]
        top_box_object := box.new(left = box_start, right = box_start+1, top=box_top, bottom=box_mid,
         extend=extend.none, xloc = xloc.bar_time, bgcolor=color.new(chart.fg_color,100), border_color = top_color, border_style=line.style_dotted)
        bot_box_object := box.new(left = box_start, right = box_start+1, top=box_mid, bottom=box_bot,
         extend=extend.none, xloc = xloc.bar_time, bgcolor=color.new(chart.fg_color,100), border_color = bot_color, border_style=line.style_dotted)

    else if box_active
        box.set_lefttop(top_box_object, box_start, box_top)
        box.set_rightbottom(top_box_object, time, box_mid)

        box.set_lefttop(bot_box_object, box_start, box_mid)
        box.set_rightbottom(bot_box_object, time, box_bot)

    top_box_object


f_draw_label(label_value, label_prefix) =>
    var label label_object = na

    if na(label_object)
        label_object := label.new(x=bar_index+label_extension, y=label_value, text = label_prefix+"="+str.tostring(label_value), xloc = xloc.bar_index,
         textalign = text.align_right, style = label.style_label_center,
         color = color.new(chart.fg_color,30), textcolor = chart.bg_color, size = size.small)

    else if label_value != label_value[1]
        label.set_text(label_object, label_prefix+"="+str.tostring(label_value))
        label.set_xy(label_object, bar_index+label_extension, label_value)

    else 
        label.set_x(label_object, bar_index+label_extension)

    label_object


f_vwap(src) =>
    var float sumSrcVol     = na
    var float sumVol        = na
    var float sumSrcSrcVol  = na

    isNewPeriod     = timeframe.change("1D")
    sumSrcVol       := isNewPeriod ? src * volume : src * volume + sumSrcVol[1]
    sumVol          := isNewPeriod ? volume : volume + sumVol[1]
    sumSrcSrcVol    := isNewPeriod ? volume * math.pow(src, 2) : volume * math.pow(src, 2) + sumSrcSrcVol[1]
    _vwap           = sumSrcVol / sumVol




// Calculate Session Vars
is_rth = time == time(timeframe.period, str.format('{0}:1234567', rth_session), 'America/New_York')
[rth_h, rth_l, rth_o, rth_c] = f_calculate_sess_ohlc(is_rth)
[p_rth_h, p_rth_l, p_rth_o, p_rth_c] = f_calculate_prior_ohlc(is_rth, rth_h, rth_l, rth_o, rth_c)

is_on = time == time(timeframe.period, str.format('{0}:1234567', on_session), 'America/New_York')
bgcolor(is_on ? color.new(#5A6471,82) : na)
[onh, onl, ono, onc] = f_calculate_sess_ohlc(is_on)

is_ib = time == time(timeframe.period, str.format('{0}:1234567', ib_session), 'America/New_York')
[ibh, ibl, ibo, ibc] = f_calculate_sess_ohlc(is_ib)

fs_vwap     = math.round_to_mintick(f_vwap(close))
vwap_color  = fs_vwap > fs_vwap[3] ? color.rgb(0, 205, 89, 50) : color.rgb(255, 0, 0, 50)
plot(fs_vwap, title = 'FS VWAP', style = plot.style_linebr, color = vwap_color)

if show_lines
    f_draw_line(rth_h, is_rth, rth_color,2)
    f_draw_line(rth_l, is_rth, rth_color,2)

    f_draw_line(onh, is_on, on_color,1)
    f_draw_line(onl, is_on, on_color,1)

    f_draw_two_box(ibh, ibl, is_ib, color.new(ibh_color,50), color.new(ibl_color,50))

if barstate.islast and show_labels
    visible_bars = math.round((chart.right_visible_bar_time-chart.left_visible_bar_time)/1000/timeframe.in_seconds())
    label_extension := 
     visible_bars > 1500 ? 200
     : visible_bars > 750 ? 100
     : visible_bars > 500 ? 55
     : visible_bars > 200 ? 35
     : 15

    f_draw_label(rth_h, "RTH High")
    f_draw_label(rth_l, "RTH Low")
    f_draw_label(rth_o, "Open")
    f_draw_label(p_rth_h, "YH")
    f_draw_label(p_rth_l, "YL")

    f_draw_label(onh, "ONH")
    f_draw_label(onl, "ONL")

    f_draw_label(ibh, "IBH")
    f_draw_label(ibl, "IBL")

    f_draw_label(fs_vwap, "VWAP")

Overview

GG - Levels calculates open, high, low, and close values for Regular Trading Hours (RTH), the Overnight Session (ON), and the Initial Balance (IB) period. It draws horizontal reference lines and range boxes for session boundaries, prior session levels, and initial balance highs and lows. Inputs allow traders to configure custom session times, toggle line and label displays, and customize level colors.

Details

Published by

g-moe on GitHub

Code credit

goodgains, as written in the script's header

Draws

On the price chart

Markets

Indices, Stocks

Timeframes

M1-M5, M15-H1

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 Linesbooltrueshow_lines
Show Labelsbooltrueshow_labels
RTHcolorcolor.new(#5A6471, 0 )rth_color
ONcolorcolor.new(#5A6471, 0 )on_color
IBHcolorcolor.new(#a5d6a7, 0)ibh_color
IBLcolorcolor.new(#faa1a4, 0)ibl_color
RTH Session (EST)session0930-1659rth_session
ON Session (EST)session1700-0929on_session
IB Session (EST)session0930-1030ib_session
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 indicator builds Market Profile Time Price Opportunity (TPO) structures across defined session timeframes directly on the main price chart. It visualizes the Point of Control (POC) and Value Area boundaries using dynamic box drawings. An integrated multi-

Indicator v5 Support & resistanceScreeners & dashboards
Updated 1 year ago · MPL-2.0 GitHub repository of Market Profile with Screener
257 stars

This indicator plots auto trade signals for E-mini S&P 500 futures on the price chart. It computes an EMA200 filter along with day ETH RTH session levels and percentage-based entry zones. Signals trigger CALL or PUT cases when price crosses defined thresholds

Indicator v6 TrendSupport & resistance
Updated 7 weeks ago · None stated GitHub repository of Auto Trade Futures ES

Golden Bullet Strategy

by TradersPost
228 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
219 stars

This indicator plots reference levels for previous daily high and low prices directly on the price chart. It requests daily timeframe data using the security function and plots the offset values as continuous lines, displaying resistance in red and support in

Indicator v4 Support & resistanceSessions & time
Updated 5 years ago · None stated GitHub repository of 昨日高低點標示

Moon Dev GEX Arrows

by moondevonyt
92 stars

This overlay indicator plots option strike walls and an optional session VWAP on the price chart for SPY or ES. It spaces major strikes by the selected instrument, draws a set number of strikes on each side, and marks wall-trap and sweep events after a cooldow

Indicator v5 Support & resistanceSessions & time
Updated 2 months ago · Custom licence GitHub repository of Moon Dev GEX Arrows

Key Levels

by cryptorife
75 stars

This indicator plots reference levels and session markers directly on the price chart. It calculates and draws lines for the daily open, weekly open, monthly open, previous day OHLC, and previous week extremes, along with a selectable day-of-week range and ini

Indicator v4 Support & resistanceSessions & time Repaints
Updated 3 years ago · GPL-3.0 GitHub repository of Key Levels

More Sessions & time scripts

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