Indicator · Pine Script v6 · Own pane

Day Candle Closed Hour(s) Ago

by chaise-cogent

This indicator calculates and plots virtual daily candlestick OHLC values shifted forward by several hours relative to the current time.

View on GitHub

GitHub stars5on the repository
Pine versionv6current
Lines of code94
Settings3inputs
LicenceMIT
Last update7 months ago19 Mar 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

94 lines of Pine Script v6 from src/day-candle-finished-hours-ago.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

day-candle-finished-hours-ago.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © chaise_cogent
//
// Script version = 1.0.0
// The script slides start/end hours of 1-day candles forward,
// as if Day candle closed 0-3 hour ago.
// For example, if now is 9:15am UTC —- then virtual days
// starts at 8:00am (i.e., closest 4-hour frame to 9:15am).

//@version=6
indicator('Day candle closed hour(s) ago', overlay=false)

show_on_real = input.bool(false, 'Show virtual levels on real 1D candles?')
bull_color = input.color(color.new(color.green, 20), title = 'Bullish Candle')
bear_color = input.color(color.new(color.gray, 20), title = 'Bearish Candle')
is_one_day_timeframe = timeframe.isdaily and timeframe.multiplier == 1

get_hour_human_readable(simple int days_back = 0) =>
    // Returns hour as a military-time string like: '13:00'
    _hour_truncated_to_4h = int(hour(timenow) / 4) * 4
    _today_start = timestamp(
      year(timenow), month(timenow), dayofmonth(timenow), _hour_truncated_to_4h, 0, 0)
    _yesterday_start = _today_start - days_back * 24 * 3600 * 1000
    str.format_time(_yesterday_start, 'HH:mm', syminfo.timezone)

last_day_custom_open = request.security(syminfo.tickerid, '240', open[6])
last_day_custom_high = request.security(syminfo.tickerid, '240', ta.highest(high[1], 6))
last_day_custom_low = request.security(syminfo.tickerid, '240', ta.lowest(low[1], 6))
last_day_custom_close = request.security(syminfo.tickerid, '240', close[1])

var int previous_days_hourly_index = 6 - int(hour(timenow) / 4) 

before_last_day_custom_open = request.security(syminfo.tickerid, '240', open[previous_days_hourly_index + 5])
before_last_day_custom_high = request.security(syminfo.tickerid, '240', ta.highest(high[previous_days_hourly_index], 6))
before_last_day_custom_low = request.security(syminfo.tickerid, '240', ta.lowest(low[previous_days_hourly_index], 6))
before_last_day_custom_close = request.security(syminfo.tickerid, '240', close[previous_days_hourly_index])

series float custom_open = na
series float custom_close = na
series float custom_high = na
series float custom_low = na

if is_one_day_timeframe
    if barstate.islast
        custom_open := last_day_custom_open
        custom_high := last_day_custom_high
        custom_low := last_day_custom_low
        custom_close := last_day_custom_close
    else
        custom_open := before_last_day_custom_open
        custom_high := before_last_day_custom_high
        custom_low := before_last_day_custom_low
        custom_close := before_last_day_custom_close
else
    custom_open := open
    custom_high := high
    custom_low := low
    custom_close := close

candle_color = custom_open <= custom_close ? bull_color : bear_color

// Main plotting of the candles
plotcandle(custom_open, custom_high, custom_low, custom_close,
  color = candle_color, wickcolor = candle_color, bordercolor = candle_color,
  title = 'OHLC', force_overlay = false)

// Table with the last candle's dates
if barstate.islast
    table_settings = table.new(position.bottom_center, columns = 1, rows = 2,
      border_color = color.white, bgcolor = color.new(color.black, 20),
      border_width = 1, force_overlay = false)

    table.clear(table_settings, start_column = 0, start_row = 0,
      end_column = 0, end_row = 1)
    table.cell(table_settings, 0, 0, 'Virtual day starts', text_size = size.tiny,
      text_color = color.white, text_formatting = text.format_bold)
    table.cell(table_settings, 0, 1, get_hour_human_readable(1) + ' UTC',
      text_size = size.small, text_color = color.white)

// Next lines are only supplementing 
// Plotting virtual candle's levels on real candles
day_open_conditional = show_on_real and is_one_day_timeframe ? custom_open : na
day_high_conditional = show_on_real and is_one_day_timeframe ? custom_high : na
day_low_conditional = show_on_real and is_one_day_timeframe ? custom_low : na
day_close_conditional = show_on_real and is_one_day_timeframe ? custom_close : na

plot(day_open_conditional, style=plot.style_circles, color = color.new(bull_color, 0),
  linewidth = 2, force_overlay = true, title = 'virt open')
plot(day_high_conditional, style=plot.style_circles, color = color.gray,
  linewidth = 2, force_overlay = true, title = 'virt high')
plot(day_low_conditional, style=plot.style_circles, color = color.gray,
  linewidth = 2, force_overlay = true, title = 'virt low')
plot(day_close_conditional, style=plot.style_circles, color = color.new(bear_color, 0),
  linewidth = 2, force_overlay = true, title = 'virt close')

Overview

By aggregating four-hour bar data from higher-timeframe requests, it constructs custom 24-hour periods and renders them as candlesticks in a separate pane alongside an information table displaying the virtual day's start time. Inputs allow users to customize bullish and bearish candle colors.

Details

Published by

chaise-cogent on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Candlestick patterns, Sessions & time, SMC / ICT / price action

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
Show virtual levels on real 1D candles?boolfalseshow_on_real
Bullish Candlecolorcolor.new(color.green, 20)bull_color
Bearish Candlecolorcolor.new(color.gray, 20)bear_color
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

3-Candle Time Pattern

by alboogycOdR
6 stars

This indicator detects three-candle time patterns on the price chart, tracking range, manipulation, and distribution phases based on Smart Money Concepts. It establishes high and low boundaries from the opening candle and identifies boundary rejections during

Indicator v5 SMC / ICT / price actionCandlestick patterns
Updated 7 months ago · None stated GitHub repository of 3-Candle Time Pattern

TheStrat Suite

by 345-strategies
5 stars

TheStrat Suite is a multi-timeframe price action indicator implementing Rob Smith's TheStrat methodology. It calculates bar classifications for inside bars, hammers, shooters, failed 2s and outside bars across configurable timeframes. The indicator detects sig

Indicator v6 SMC / ICT / price actionCandlestick patterns Repaints
Updated 2 days ago · MPL-2.0 GitHub repository of TheStrat Suite
2 stars

This indicator detects liquidity sweeps during the Asian session and identifies reversal opportunities in the New York session. It tracks the high and low of the Asia trading range using session timestamps in UTC+3. Sweep up and down are flagged when price bre

Indicator v5 SMC / ICT / price actionSessions & time
Updated 2 months ago · None stated GitHub repository of Asian Liquidity Sweep + NY Reversal
2 stars

Session Extreme Revisit identifies the highest supply candle and lowest demand candle formed during London and New York sessions and draws extended reaction zones on the price chart. It evaluates candidate candles using size, wick ratio, and displacement filte

Indicator v5 Sessions & timeSupport & resistance
Updated 5 months ago · None stated GitHub repository of Session Extreme Revisit — Pro

AmiComStrategy

by amico1234
1 stars

AmiComStrategy is an indicator that calculates correlations between securities using the Corell indicator over specified timeframes such as 5D. It filters trading opportunities based on session times like 1300-1700 and security up and down times such as 3H. Th

Indicator v4 Sessions & timeVolatility & bands
Updated 2 years ago · None stated GitHub repository of AmiComStrategy

SMC Context Bus

by skipp-dev
1 stars

This indicator builds a smart-money context frame in a separate pane by calling a private context engine. It exposes hidden numeric plots for schema version, readiness, bias, quality, market structure including break of structure and change of character, imbal

Indicator v6 SMC / ICT / price actionSupport & resistance
Updated 2 days ago · None stated GitHub repository of SMC Context Bus

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