Indicator · Pine Script v6 · Own pane

Week candle backward shift

by chaise-cogent

This indicator rebuilds one-week candles so their start day is shifted backward by a chosen number of days, from zero through six.

View on GitHub

GitHub stars5on the repository
Pine versionv6current
Lines of code90
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

90 lines of Pine Script v6 from src/week-candle-start-day-backward-shift.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

week-candle-start-day-backward-shift.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 = 2.1-reduced logs
// The script slides start date of 1-WEEK candles to the specified number of days BACKWARD
// For example, "shift_days = 1" means that candles start on Sunday and the last day is Monday

//@version=6
indicator("Week candle backward shift", overlay=false, max_bars_back = 20)

var shift_days = input.int(0, title = "Days to shift backward", minval=0, maxval=6)
bull_color = input.color(color.new(color.green, 20), title = "Bullish Candle")
bear_color = input.color(color.new(color.red, 20), title = "Bearish Candle")

var int start_day_index = dayofweek + shift_days + 1
var int end_day_index = start_day_index - 6

var int last_candle_week_length = if dayofweek(timenow) == dayofweek.monday
    shift_days + 1
else if dayofweek(timenow) == dayofweek.tuesday
    shift_days + 2
else if dayofweek(timenow) == dayofweek.wednesday
    shift_days + 3
else if dayofweek(timenow) == dayofweek.thursday
    shift_days + 4
else if dayofweek(timenow) == dayofweek.friday
    shift_days + 5
else if dayofweek(timenow) == dayofweek.saturday
    shift_days + 6
else // SUNDAY
    shift_days + 7
log.info('current-day={0}, last-candle-week-len={1}',
  dayofweek(time_close(timeframe.period)), last_candle_week_length)

var int last_candle_start_index = if dayofweek(timenow) == dayofweek.monday
    shift_days + 0
else if dayofweek(timenow) == dayofweek.tuesday
    shift_days + 1
else if dayofweek(timenow) == dayofweek.wednesday
    shift_days + 2
else if dayofweek(timenow) == dayofweek.thursday
    shift_days + 3
else if dayofweek(timenow) == dayofweek.friday
    shift_days + 4
else if dayofweek(timenow) == dayofweek.saturday
    shift_days + 5
else // SUNDAY
    shift_days + 6
log.info('current-day={0}, day-bar-start-index={1}',
  dayofweek(time_close(timeframe.period)), last_candle_start_index)

dailyOpen = request.security(syminfo.tickerid, "1D", open[start_day_index])
dailyHigh = request.security(syminfo.tickerid, "1D", ta.highest(high[end_day_index], 7))
dailyLow = request.security(syminfo.tickerid, '1D', ta.lowest(low[end_day_index], 7))
dailyClose = request.security(syminfo.tickerid, "1D", close[end_day_index])

// Special case for the current (unclosed) candle which length changes from 1 to 7 days
daily_open_last_candle = request.security(syminfo.tickerid, "1D", open[last_candle_start_index]) 
daily_high_last_candle = request.security(syminfo.tickerid, "1D", ta.highest(high[0], last_candle_week_length))
daily_low_last_candle = request.security(syminfo.tickerid, '1D', ta.lowest(low[0], last_candle_week_length))
daily_close_last_candle = request.security(syminfo.tickerid, "1D", close[0])

// Assign Weekly values to the custom open/high/low/close variables
var series float custom_open = na
var series float custom_close = na
var series float custom_high = na
var series float custom_low = na
if timeframe.isweekly and timeframe.multiplier == 1
    if bar_index != last_bar_index
        custom_open := dailyOpen
        custom_high := dailyHigh
        custom_low := dailyLow
        custom_close := dailyClose
    else
        custom_open := daily_open_last_candle
        custom_high := daily_high_last_candle
        custom_low := daily_low_last_candle
        custom_close := daily_close_last_candle
else
    custom_open := open
    custom_high := high
    custom_low := low
    custom_close := close

is_green = custom_open <= custom_close
candle_color = is_green ? bull_color : bear_color

plotcandle(custom_open, custom_high, custom_low, custom_close,
  color = candle_color, wickcolor = candle_color, bordercolor = candle_color,
  title = 'OHLC', force_overlay = false)

Overview

On a weekly chart it requests daily open, high, low, and close and assigns them to custom weekly values, with a separate calculation for the still-open current week. On other timeframes it uses the chart's own OHLC. Users set the day shift and bullish and bearish colors. It plots in a separate pane and does not generate entries or exits. The repository notes that this version is outdated.

Details

Published by

chaise-cogent on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Candlestick patterns, Sessions & time

Markets

Any symbol

Timeframes

H4 and above

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
Days to shift backwardint0shift_days
Bullish Candlecolorcolor.new(color.green, 20)bull_color
Bearish Candlecolorcolor.new(color.red, 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

56 stars

This overlay indicator highlights candles with a body smaller than 50% of their total range by coloring them white on the price chart. Simultaneously, it calculates and plots horizontal lines for open prices across multiple higher timeframes, such as daily, we

Indicator v6 Support & resistanceCandlestick patterns Repaints
Updated 2 months ago · None stated GitHub repository of Daily Weekly Monthly Yearly Opens

Zen OOH OOL v3

by Zen-Tim
29 stars

This indicator identifies whether the opening bar of a new trading day opens at its high (Open = High) or low (Open = Low) within a customizable tick tolerance. It marks matching sessions directly on the price chart using directional arrows, text labels, and t

Indicator v5 Sessions & timeCandlestick patterns
Updated 2 weeks ago · MIT GitHub repository of Zen OOH OOL v3
23 stars

Point-Clip Unified Indicator plots breakout and directional labels on the price chart. It scores volume spikes against a volume average, range or opening-range breaks, optional VWAP or session-anchored VWAP, fast and slow EMA trend, and a higher-timeframe EMA

Indicator v6 BreakoutVolume Repaints
Updated 3 weeks ago · Custom licence GitHub repository of Point-Clip Unified Indicator
7 stars

Multi-Ticker Anchored Candles overlays up to three user-selected symbols on the price chart as candles anchored to a chosen period, which defaults to the daily timeframe. Each symbol has its own color and an on or off toggle. Optional drawings mark session bre

Indicator v6 Candlestick patternsSessions & time
Updated 3 months ago · None stated GitHub repository of Multi-Ticker Anchored Candles

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

BPA [yohtza]

by forecho
5 stars

This indicator plots key session-based price action reference levels on the price chart. It calculates and displays the current session open, previous day close, Globex session high and low, weekly open, and higher-timeframe boundaries. It also supports bar co

Indicator v6 Sessions & timeSupport & resistance
Updated 8 weeks ago · None stated GitHub repository of BPA [yohtza]

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