Indicator · Pine Script v5 · On the chart

GARY - Prior Levels

by g-moe· code credited to goodgains

This indicator calculates and plots previous higher-timeframe structural levels directly onto the main price chart.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code78
Settings7inputs
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

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

gary-prior-levels.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © goodgains


//@version=5
indicator("GARY - Prior Levels", overlay= true, max_labels_count = 500, max_boxes_count = 500, max_lines_count = 500, max_bars_back = 5000)

// @keywords: prior-levels, prior-high, prior-low, prior-close, prior-mid, multi-timeframe, day-structure, week-structure, month-structure, horizontal-lines, level-labels, mtf-levels, dashed-lines, price-levels, session-levels, historical-levels, extend-right, reference-levels, structure-lines, gary-levels

//--MTF STRUCTURE INPUTS--//
mtf_showday = input.bool(true, title = 'Day Structure', group = 'Multi-Timeframe Structure (MTF) Settings', inline = '1')
mtf_day_css = input.color(color.new(color.white,70), title = '', group = 'Multi-Timeframe Structure (MTF) Settings', inline = '1')
mtf_showweek = input.bool(false, title = 'Week Structure', group = 'Multi-Timeframe Structure (MTF) Settings', inline = '2')
mtf_week_css = input.color(color.new(color.white,70), title = '', group = 'Multi-Timeframe Structure (MTF) Settings', inline = '2')
mtf_showmonth = input.bool(false, title = 'Month Structure', group = 'Multi-Timeframe Structure (MTF) Settings', inline = '3')
mtf_month_css = input.color(color.new(color.white,70), title = '', group = 'Multi-Timeframe Structure (MTF) Settings', inline = '3')
mtf_label_css = input.color(color.new(color.white, 60), title = 'Label', group = 'Multi-Timeframe Structure (MTF) Settings', inline = '5')
//-----INPUTS-----//


//--FUNCTION FOR GETTING MTF VALUES AND PLOTTING THEM--//
f_mtf_values(time_period, bar_start, line_color, label_color, label_text , tooltip_text) =>
    
    highs = request.security(syminfo.tickerid,time_period, high[1], lookahead=barmerge.lookahead_on)
    lows = request.security(syminfo.tickerid,time_period, low[1], lookahead=barmerge.lookahead_on)
    closes = request.security(syminfo.tickerid,time_period, close[1], lookahead=barmerge.lookahead_on)
    
    var prior_high_line = array.new_line(0, na)
    var prior_high_label = array.new_label(0, na)

    array.insert(prior_high_line, 0, line.new(bar_start, highs, bar_index, y2 = highs, xloc = xloc.bar_index, extend = extend.right, color = 
     line_color, style = line.style_dashed, width = 1))
    array.insert(prior_high_label, 0, label.new(x = bar_index + 70, y = highs, text = label_text + "H", style = label.style_none, 
     size = size.tiny, textcolor = label_color, tooltip = tooltip_text + "High " + str.tostring(highs)))

    var prior_low_line = array.new_line(0, na)
    var prior_low_label = array.new_label(0, na)

    array.insert(prior_low_line, 0, line.new(bar_start, lows, bar_index, y2 = lows, xloc = xloc.bar_index, extend = extend.right, color = 
     line_color, style = line.style_dashed, width = 1))
    array.insert(prior_low_label, 0, label.new(x = bar_index + 70, y = lows, text = label_text + "L", style = label.style_none, 
     size = size.tiny, textcolor = label_color, tooltip = tooltip_text + "Low " +str.tostring(lows)))

    var prior_close_line = array.new_line(0, na)
    var prior_close_label = array.new_label(0, na)

    array.insert(prior_close_line, 0, line.new(bar_start, closes, bar_index, y2 = closes, xloc = xloc.bar_index, extend = extend.right, color = 
     line_color, style = line.style_dashed, width = 1))
    array.insert(prior_close_label, 0, label.new(x = bar_index + 70, y = closes, text = label_text + "C", style = label.style_none, 
     size = size.tiny, textcolor = label_color, tooltip = tooltip_text + "Close " +str.tostring(closes)))

    var prior_mid_line = array.new_line(0, na)
    var prior_mid_label = array.new_label(0, na)

    array.insert(prior_mid_line, 0, line.new(bar_start, (highs + lows) / 2, bar_index, y2 = (highs + lows) / 2, xloc = xloc.bar_index, extend = extend.right, color = 
     line_color, style = line.style_dashed, width = 1))
    array.insert(prior_mid_label, 0, label.new(x = bar_index + 70, y = (highs + lows) / 2, text = label_text + "M", style = label.style_none, 
     size = size.tiny, textcolor = label_color, tooltip = tooltip_text + "Mid " +str.tostring((highs + lows) / 2)))
//--FUNCTION FOR GETTING MTF VALUES AND PLOTTING THEM--//


// time changes for mtf
var int day_bn_start = 0
day_bn_start := ta.change(time('D')) ? bar_index : day_bn_start[1]

var int week_bn_start = 0
week_bn_start := ta.change(time('W')) ? bar_index : day_bn_start[1]

var int month_bn_start = 0
month_bn_start := ta.change(time('M')) ? bar_index : day_bn_start[1]

if barstate.islastconfirmedhistory
    if mtf_showday
        f_mtf_values('D', day_bn_start, mtf_day_css, mtf_label_css, 'PD', 'Prior Days ')
    if mtf_showweek
        f_mtf_values('W', week_bn_start, mtf_week_css, mtf_label_css, 'PW', 'Prior Weeks ')
    if mtf_showmonth
        f_mtf_values('M', month_bn_start, mtf_month_css, mtf_label_css, 'PM', 'Prior Months ')

Overview

GARY - Prior Levels retrieves the prior high, low, and close levels for daily, weekly, and monthly periods using dashed horizontal reference lines and labels extended to the right. Users can individually toggle visibility and customize the line and label colors for day, week, and month structures.

Details

Published by

g-moe on GitHub

Code credit

goodgains, as written in the script's header

Draws

On the price chart

Markets

Any symbol

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
Day Structurebooltruemtf_showday
mtf_day_csscolorcolor.new(color.white,70)mtf_day_css
Week Structureboolfalsemtf_showweek
mtf_week_csscolorcolor.new(color.white,70)mtf_week_css
Month Structureboolfalsemtf_showmonth
mtf_month_csscolorcolor.new(color.white,70)mtf_month_css
Labelcolorcolor.new(color.white, 60)mtf_label_css
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 Support & resistance 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