Indicator · Pine Script v5 · On the chart

XAUUSD Hour Range Reference

by teshmi9z-beep

An intraday indicator designed for gold that takes the high and low of one chosen hourly candle, set by an hour input, and extends them across the rest of the day as reference lines.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code73
Settings7inputs
LicenceMIT
Last updateyesterday28 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

73 lines of Pine Script v5 from src/indicators/custom/hourRange.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

hourRange.pine
//@version=5
indicator("XAUUSD 19h - 1H Closed Ref", overlay=true, max_lines_count=500)

// --- Condition d'unité de temps (Inférieur au Daily) ---
isAllowed = timeframe.isintraday

// --- Paramètres ---
targetHour   = input.int(18, "Heure de la bougie (ex: 18 pour 18h-19h)", minval=0, maxval=23)
candleColor  = input.color(color.new(#ff6803, 50), "Couleur Bougie cible")

// --- Paramètres de Style ---
highColorSetting = input.color(color.green, "Couleur High", group="Style High")
highStyleSetting  = input.string("Solid", "Style High", options=["Solid", "Dashed", "Dotted"], group="Style High")
lowColorSetting  = input.color(color.red, "Couleur Low", group="Style Low")
lowStyleSetting   = input.string("Solid", "Style Low", options=["Solid", "Dashed", "Dotted"], group="Style Low")
lineWidth        = input.int(2, "Épaisseur", minval=1)

// --- Récupération des données 1H ---
[h1h, l1h] = request.security(syminfo.tickerid, "60", [high[1], low[1]], lookahead=barmerge.lookahead_on)

// --- Logique de détection ---
var float refHigh = na
var float refLow  = na
var line lineH    = na
var line lineL    = na
var int bias      = 0

isNewDay = ta.change(time("D"))

// On utilise l'heure du graphique (hour)
isClotureTarget = hour[1] == targetHour and hour != targetHour

// On n'exécute la logique de création que si on est en Intraday
if isAllowed and isClotureTarget
    refHigh := h1h
    refLow  := l1h
    bias    := 0

    // Dessin des segments
    lineH := line.new(bar_index, refHigh, bar_index, refHigh, color=highColorSetting, width=lineWidth, style=(highStyleSetting == "Solid" ? line.style_solid : highStyleSetting == "Dashed" ? line.style_dashed : line.style_dotted))
    lineL := line.new(bar_index, refLow, bar_index, refLow, color=lowColorSetting, width=lineWidth, style=(lowStyleSetting == "Solid" ? line.style_solid : lowStyleSetting == "Dashed" ? line.style_dashed : line.style_dotted))

// Extension des lignes (uniquement si autorisé)
if isAllowed and not na(refHigh) and not isNewDay
    line.set_x2(lineH, bar_index)
    line.set_x2(lineL, bar_index)

// Définition du Biais
if isAllowed and not na(refHigh)
    if close > refHigh
        bias := 1
    else if close < refLow
        bias := -1

// Reset pour le lendemain
if isNewDay
    refHigh := na
    refLow  := na
    bias    := 0

// --- Affichage ---

// Background (seulement si isAllowed)
bgcolor(isAllowed and bias == 1 ? color.new(highColorSetting, 90) : isAllowed and bias == -1 ? color.new(lowColorSetting, 90) : na)

// Coloration des bougies (seulement si isAllowed)
isInsideTarget = hour == targetHour
barcolor(isAllowed and isInsideTarget ? candleColor : na)

// Signaux (seulement si isAllowed)
biasChanged = ta.change(bias)
plotshape(isAllowed and biasChanged and bias == 1, "Breakout Haut", shape.triangleup, location.belowbar, color.green, size=size.small)
plotshape(isAllowed and biasChanged and bias == -1, "Breakout Bas", shape.triangledown, location.abovebar, color.red, size=size.small)

Overview

A background tint and triangle markers show when price closes above the high or below the low, setting a bullish or bearish bias that resets each day. The chosen hour candle is coloured on the chart. It works only on intraday timeframes and draws on the price chart.

Details

Published by

teshmi9z-beep on GitHub

Draws

On the price chart

Markets

Gold

Timeframes

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
Heure de la bougie (ex: 18 pour 18h-19h)int18targetHour
Couleur Bougie ciblecolorcolor.new(#ff6803, 50)candleColor
Couleur Highcolorcolor.greenhighColorSetting
Style HighstringSolidhighStyleSetting
Couleur Lowcolorcolor.redlowColorSetting
Style LowstringSolidlowStyleSetting
Épaisseurint2lineWidth
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

IB / ORB Live Stats

by TamaraKGreen
46 stars

This overlay indicator marks the New York initial balance and a configurable opening range on the price chart and reports live range statistics in two tables. It builds an IB box for a default 09:30–10:30 ET window, an ORB box from 09:30 for a set number of mi

Indicator v6 Sessions & timeBreakout
Updated 7 weeks ago · None stated GitHub repository of IB / ORB Live Stats

Zen-DAX GX

by Zen-Tim
29 stars

This indicator calculates and plots session ranges and key breakout levels for DAX futures directly on the price chart. It defines the overnight Globex session, the Frankfurt pre-market range, and the regular trading hours open using European timezone settings

Indicator v5 Sessions & timeBreakout
Updated 2 weeks ago · MIT GitHub repository of Zen-DAX GX

ORB Pro - Research-Based ORB

by Mrshahidali420
16 stars

The ORB Pro indicator calculates and plots Opening Range Breakout levels, stop-loss and take-profit zones, signal labels, and an status dashboard on the price chart. Built on academic research, it evaluates trades using an opening-candle direction filter, open

Indicator v6 BreakoutSessions & time Repaints
Updated 3 months ago · None stated GitHub repository of ORB Pro - Research-Based ORB

Nexural ORB

by JasonTeixeira
9 stars

This indicator plots opening range breakout levels across multiple timeframes, including five, fifteen, thirty, and sixty minutes, directly on the price chart. It also displays the session open and overnight high and low levels. The script calculates an openin

Indicator v6 BreakoutSessions & time
Updated 13 days ago · Custom licence GitHub repository of Nexural ORB

FX Market Sessions

by itmakesyousick
7 stars

FX Market Sessions highlights distinct trading sessions, such as London, New York, and Tokyo, directly on the main price chart. It draws background boxes for each active session and optionally plots opening ranges, Fibonacci retracement levels, and session ext

Indicator v5 Sessions & timeSupport & resistance
Updated 3 years ago · None stated GitHub repository of FX Market Sessions

Gold Breakout Trader

by eddiebelaval
7 stars

Plots timed breakout ranges directly on the price chart, designed for gold trading using dollar-based spacing. At scheduled trigger times or recurring two-hour intervals, it creates a central reference box flanked by upper and lower breakout stop lines, follow

Indicator v6 BreakoutSupport & resistance
Updated 3 months ago · None stated GitHub repository of Gold Breakout Trader

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